
; Asar directives
hirom
org $C30000
table ff6_bank_c3.tbl,rtl
incsrc ff6_bank_c3_defs.asm


; Entry points
C30000:  JMP C3001B      ; Invoke desired field menu
C30003:  JMP C3A445      ; Decode joypads for battle
C30006:  JMP C3A424      ; Initialize joypad data
C30009:  JMP C3A47A      ; Decode joypads for field
C3000C:  JMP C313C8      ; Advance play time
C3000F:  JMP C314FE      ; Load save data on defeat
C30012:  JMP C3C51C      ; Show an ending cinematic
C30015:  JMP C396D2      ; Optimize member's gear
C30018:  JMP C3D57F      ; Load map for final land

; Invoke requested field menu
C3001B:  REP #$10        ; 16-bit X, Y
         SEP #$20        ; 8-bit A
         LDA #$00        ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         LDX #$0000      ; Zero X
         PHX             ; Put on stack
         PLD             ; Set DP to 0
         LDX #$0000      ; ...
         STX $00         ; Optimzn word: 0
         LDA #$7E        ; Bank: 7E
         STA $2183       ; Set WRAM HB
         JSR C300C0      ; Reroute NMI/IRQ
         LDA $0200       ; Menu to open
         CMP #$02        ; Load menu?
         BNE C3003F      ; Branch if not
         JSR C3709B      ; Reset game data
C3003F:  JSR C300F8      ; Load GFX, colors
         JSR C300DD      ; Handle menu
         JSL C3A424      ; Get joypad config
         LDA #$8F        ; BRT: 15 and OFF
         STA $2100       ; Disable screen
         STZ $4200       ; Disable INT, pad
         STZ $420B       ; Disable DMA...
         STZ $420C       ; Disable HDMA

; Fork: Leaving Load menu
C30057:  LDA $0200       ; Menu closed
         CMP #$02        ; Load menu?
         BNE C3006F      ; Branch if not
         LDA $0205       ; Start new game?
         BPL C3006F      ; Branch if so
         LDA $1D4E       ; Game options
         AND #$20        ; Stereo sound?
         BEQ C3006F      ; Branch if so
         LDA #$FF        ; Mode: Mono
         JSR C33E3F      ; Adjust volume

; Fork: Rename Card
C3006F:  LDA $0200       ; In main menu?
         BNE C300BF      ; Return if not
         LDA $0205       ; Rename request?
         BPL C300BF      ; Return if not
         CMP #$FE        ; Rename actor?
         BNE C3009E      ; SwdTech if not
         LDA #$01        ; Actor renaming
         STA $0200       ; Set menu number
         LDA $0201       ; Area permissions
         STA $020F       ; Preserve them
         LDY $0206       ; Actor's address
         STY $0201       ; Set as target's
         JSL C30000      ; Call naming menu
         LDA $020F       ; Area permissions
         STA $0201       ; Restore them
         STZ $0200       ; Menu: Main
         JMP C3001B      ; Open main menu

; Fork: SwdTech renaming (SFC)
C3009E:  LDA #$06        ; SwdTech renaming
         STA $0200       ; Set menu number
         LDA $0201       ; Area permissions
         STA $020F       ; Preserve them
         LDA $0206       ; Chosen SwdTech
         STA $0201       ; Set as target
         JSL C30000      ; Call naming menu
         LDA $020F       ; Area permissions
         STA $0201       ; Restore them
         STZ $0200       ; Menu: Main
         JMP C3001B      ; Open main menu
C300BF:  RTL

; Reroute interrupt vectors
C300C0:  LDA #$5C        ; JML opcode
         STA $1500       ; Put by NMI loc
         STA $1504       ; Put by IRQ loc
         LDX #C31387     ; C3/1387
         STX $1501       ; Set NMI LBs
         LDX #C313C7     ; C3/13C7
         STX $1505       ; Set IRQ LBs
         LDA #$C3        ; Bank: C3
         STA $1503       ; Set NMI HB
         STA $1507       ; Set IRQ HB
         RTS

; Access requested field menu
C300DD:  TDC             ; Clear A
         LDA $0200       ; Menu to open
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C300E6,X)  ; Invoke menu

; Jump table for the above
C300E6:  dw C3011A       ; Main menu
         dw C301B3       ; Actor naming
         dw C3016F       ; Load menu
         dw C30121       ; Shop
         dw C3012B       ; Lineup
         dw C3013D       ; Bogus...
         dw C30149       ; SwdTech naming
         dw C30152       ; Colosseum
         dw C30166       ; Final battle lineup

; Load menu graphics and colors; initialize general variables
C300F8:  JSR C368FA      ; Reset variables
         JSR C36915      ; Get party info
         JSR C369A9      ; No use...
         JSL $D4CD48     ; Init registers
         JSL C3A424      ; Init joypad data
         TDC             ; Gradient set: 0
         JSL $D4CA1D     ; Create gradient
         JSR C369DC      ; Queue Win1 HDMA
         JSR C31114      ; Reset OAM, queue
         JSR C36A87      ; Load nonskin GFX
         JMP C33A87      ; Load skin visuals

; Invoke main menu
C3011A:  LDA #$04        ; C3/1A8A
         STA $26         ; Next: Init menu
         JMP C301BA      ; Enter menu loop

; Invoke shop menu
C30121:  JSR C33F99      ; Apply user font
         LDA #$24        ; C3/B466
         STA $26         ; Next: Init menu
         JMP C301BA      ; Enter menu loop

; Invoke Lineup menu
C3012B:  JSR C33F99      ; Apply user font
         JSR C30138      ; Clear saved cursor
         LDA #$2C        ; C3/70E7
         STA $26         ; Next: Init menu
         JMP C301BA      ; Enter menu loop

; Clear cursor position restored from Lineup's Status menu...
C30138:  TDC             ; Clear A
         TAY             ; Clear Y
         STY $8E         ; Clear position
         RTS

; Invoke bogus Lineup menu...
C3013D:  JSR C33F99      ; Apply user font
         JSR C30138      ; Clear saved cursor
         LDA #$2F        ; C3/7AE5
         STA $26         ; Next: Bogus...
         BRA C301BA      ; Enter menu loop

; Invoke SwdTech naming menu (SFC)
C30149:  JSR C33F99      ; Apply user font
         LDA #$3F        ; C3/B437
         STA $26         ; Next: Bogus...
         BRA C301BA      ; Enter menu loop

; Invoke Colosseum menu
C30152:  JSR C33F99      ; Apply user font
         STZ $79         ; Never read...
         STZ $7A         ; Never read...
         STZ $7B         ; Never read...
         LDA #$FF        ; Empty item
         STA $0205       ; Will gain 1...
         LDA #$71        ; C3/ACAA
         STA $26         ; Next: Init menu
         BRA C301BA      ; Enter menu loop

; Invoke final battle lineup
C30166:  JSR C33F99      ; Apply user font
         LDA #$73        ; C3/A9F8
         STA $26         ; Next: Init menu
         BRA C301BA      ; Enter menu loop

; Invoke Load menu
C3016F:  LDA $307FF1     ; RNG index in SRAM
         INC A           ; RNG index +1
         STA $307FF1     ; Save changes
         JSL C3A424      ; Init joypad data
         JSR C37023      ; Test SRAM markers
         BCC C3019F      ; Abort if invalid
         LDA #$01        ; Song: The Prelude
         STA $1301       ; Set I/O port 1
         LDA #$10        ; APU command
         STA $1300       ; Set I/O port 0
         LDA #$80        ; Volume specs
         STA $1302       ; Set I/O port 2
         JSL $C50004     ; Play song
         LDA #$FF        ; New game: No
         STA $0205       ; Preset exit mode
         LDA #$20        ; C3/1D03
         STA $26         ; Next: Init menu
         BRA C301BA      ; Enter menu loop

; Fork: Force new game
C3019F:  JSR C32A21      ; Reset play time
         LDA #$01        ; Save slot: 1
         STA $0224       ; Set last viewed
         STZ $021F       ; Game's file: None
         LDA #$FF        ; Null value
         STA $26         ; Next: Exit menu
         STZ $0205       ; Set new game mode
         BRA C301BA      ; Enter menu loop

; Invoke actor naming menu
C301B3:  JSR C33F99      ; Apply user font
         LDA #$5D        ; C3/652D
         STA $26         ; Next: Init menu

; Main loop for field menus
C301BA:  JSR C31412      ; Refresh screen
C301BD:  TDC             ; Clear A
         LDA $26         ; Menu command
         CMP #$FF        ; Exit to map?
         BEQ C301D8      ; Branch if so
         REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         JSR (C301DB,X)  ; Handle menu cmd
         JSR C311B0      ; Handle anim queue
         JSR C3134D      ; Update screen/pad
         JSR C302DB      ; Check event timer
         BRA C301BD      ; Loop
C301D8:  STZ $43         ; Disable HDMA
         RTS

; Jump table for the above
C301DB:  dw C31D71       ; 00: Fade out screen
         dw C31D7E       ; 01: Fade in screen
         dw C31D8B       ; 02: Wait while menu fades in or out
         dw C31D94       ; 03: Exit main menu's portrait area
         dw C31A8A       ; 04: Initialize main menu
         dw C31DA4       ; 05: Sustain main menu
         dw C31DE8       ; 06: Target one actor in main menu
         dw C31AD6       ; 07: Initialize Item menu
         dw C31EF7       ; 08: Handle Item menu choice 1
         dw C31B5B       ; 09: Initialize Skills menu
         dw C31FF4       ; 0A: Sustain Skills menu
         dw C31C46       ; 0B: Initialize Status menu
         dw C321F5       ; 0C: Sustain Status menu
         dw C31C7D       ; 0D: Initialize Config menu
         dw C322C5       ; 0E: Sustain Config menu
         dw C3240C       ; 0F: Handle Order menu choice 1
         dw C32453       ; 10: Handle Order menu choice 2
         dw C324A9       ; 11: Switch members in Order menu
         dw C32537       ; 12: Wait while member changes row
         dw C31CA0       ; 13: Initialize Save menu
         dw C32540       ; 14: Sustain Save menu
         dw C31CE3       ; 15: Initialize save confirmation
         dw C3259D       ; 16: Sustain save confirmation
         dw C325F4       ; 17: Handle Item menu options
         dw C32741       ; 18: Sustain rare item menu
         dw C32779       ; 19: Handle Item menu choice 2
         dw C327E2       ; 1A: Sustain Magic menu
         dw C3288A       ; 1B: Sustain Lore menu
         dw C328AA       ; 1C: Sustain Dance menu
         dw C328BA       ; 1D: Sustain Rage menu
         dw C328D3       ; 1E: Handle esper selection
         dw C3259D       ; 1F: Unused duplicate...
         dw C31D03       ; 20: Initialize Load menu
         dw C329C2       ; 21: Sustain Load menu
         dw C31D51       ; 22: Initialize load confirmation
         dw C32A2A       ; 23: Sustain load confirmation
         dw C3B466       ; 24: Initialize shop menu
         dw C3B49B       ; 25: Sustain main shop menu
         dw C3B4BD       ; 26: Handle buy item list
         dw C3B505       ; 27: Handle buy order menu
         dw C3B60E       ; 28: Return to Buy menu after delay
         dw C3B616       ; 29: Handle sell item list
         dw C3B676       ; 2A: Handle sell order menu
         dw C3B752       ; 2B: Return to Sell menu after delay
         dw C370E7       ; 2C: Initialize Lineup menu
         dw C37168       ; 2D: Handle Lineup menu choice 1
         dw C3720C       ; 2E: Handle Lineup menu choice 2
         dw C37AE5       ; 2F: Bogus...
         dw C37B25       ; 30: Bogus...
         dw C37B25       ; 31: Bogus...
         dw C37B25       ; 32: Bogus...
         dw C32977       ; 33: Sustain Blitz menu
         dw C3293A       ; 34: Wait while showing who holds esper
         dw C31BB8       ; 35: Initialize Equip menu
         dw C39621       ; 36: Handle Equip menu options
         dw C31EB5       ; 37: Handle multitargeting in main menu
         dw C31C32       ; 38: Initialize party gear overview
         dw C32966       ; 39: Sustain party gear overview
         dw C32A65       ; 3A: Initialize spell usage menu
         dw C32AAE       ; 3B: Handle single-target spell
         dw C32D1C       ; 3C: Return to Magic menu
         dw C32D78       ; 3D: Handle multitarget spell
         dw C3298E       ; 3E: Sustain SwdTech menu
         dw C3B437       ; 3F: SFC: Initialize SwdTech naming menu
         dw C3B437       ; 40: SFC: Handle SwdTech naming choice 1
         dw C3B437       ; 41: SFC: Handle SwdTech naming choice 2
         dw C3631D       ; 42: Initialize Lineup's Status menu
         dw C3633F       ; 43: Sustain Lineup's Status menu
         dw C37D1C       ; 44: Bogus...
         dw C37D1C       ; 45: Bogus...
         dw C37D1C       ; 46: Bogus...
         dw C342C2       ; 47: Initialize Cmd.Set menu
         dw C342DF       ; 48: Handle Cmd.Set menu member selection
         dw C346AD       ; 49: SFC: Initialize Button Settings menu
         dw C346AD       ; 4A: SFC: Sustain Button Settings menu
         dw C346AD       ; 4B: Initialize Controller menu
         dw C346CA       ; 4C: Sustain Controller menu
         dw C358CE       ; 4D: Sustain esper data menu
         dw C3B437       ; 4E: SFC: Scroll to SwdTech naming page 2
         dw C3B437       ; 4F: SFC: Scroll to SwdTech naming page 1
         dw C33A00       ; 50: Scroll to Config page 2
         dw C33A21       ; 51: Scroll to Config page 1
         dw C31A0A       ; 52: Queue fade-in for save menu
         dw C319FB       ; 53: Queue fade-out for save menu
         dw C31A19       ; 54: Wait while save menu fades in or out
         dw C39884       ; 55: Handle selection of gear slot to fill
         dw C398CF       ; 56: Handle manual gear removal
         dw C3990F       ; 57: Handle gear browsing
         dw C39E4B       ; 58: Initialize Relic menu
         dw C39EB8       ; 59: Handle Relic menu options
         dw C39FFD       ; 5A: Handle selection of relic slot to fill
         dw C3A097       ; 5B: Handle relic browsing
         dw C3A10A       ; 5C: Handle relic removal
         dw C3652D       ; 5D: Initialize actor naming menu
         dw C389E6       ; 5E: Sustain shifted gear data menu
         dw C3656C       ; 5F: Sustain actor naming menu
         dw C365E8       ; 60: SFC: Scroll to actor naming page 2
         dw C365E8       ; 61: SFC: Scroll to actor naming page 1
         dw C34338       ; 62: Handle Cmd.Set menu command choice 1
         dw C34376       ; 63: Handle Cmd.Set menu command choice 2
         dw C38983       ; 64: Sustain non-shifted gear data menu
         dw C336E7       ; 65: Shift screen
         dw C379FF       ; 66: Queue fade-in for Lineup menu
         dw C379F0       ; 67: Queue fade-out for Lineup menu
         dw C37A0E       ; 68: Wait while Lineup menu fades in or out
         dw C37A87       ; 69: Erase warning in Lineup menu after delay
         dw C363A7       ; 6A: Sustain shifted Status menu
         dw C322B4       ; 6B: Unknown, unused menu mode...
         dw C39FB1       ; 6C: Handle delayed fade-out for Reequip
         dw C31C1A       ; 6D: Open Equip menu after optimizing gear
         dw C31C26       ; 6E: Open Equip menu after removing all gear
         dw C38A84       ; 6F: Initialize item usage menu
         dw C38A96       ; 70: Sustain item usage menu
         dw C3ACAA       ; 71: Initialize Colosseum item menu
         dw C3ACDC       ; 72: Sustain Colosseum item menu
         dw C3A9F8       ; 73: Initialize final battle lineup
         dw C3AA25       ; 74: Sustain final battle lineup
         dw C3ADB7       ; 75: Initialize Colosseum matchup menu
         dw C3AE0F       ; 76: Sustain Colosseum matchup menu
         dw C31B35       ; 77: Return from item usage menu
         dw C3AD8A       ; 78: Bogus...
         dw C39E7D       ; 79: Swap actor in Relic menu, retain Equip mode
         dw C39E8B       ; 7A: Swap actor in Relic menu, retain Remove mode
         dw C30000       ; 7B: Bogus...
         dw C30000       ; 7C: Bogus...
         dw C37131       ; 7D: Return to Lineup menu from Status menu
         dw C31BE5       ; 7E: Swap actor in Equip menu, retain Equip mode
         dw C31BF3       ; 7F: Swap actor in Equip menu, retain Remove mode

; Set to exit menu if event countdown timer expired
C302DB:  LDA $B4         ; Already handled?
         BNE C302F8      ; Exit if so
         LDA $1188       ; Timer 0 flags
         BIT #$20        ; Abort if expired?
         BEQ C302F8      ; Exit if not
         LDY $1189       ; Timer expired?
         BNE C302F8      ; Exit if not
         LDA #$FF        ; Null value
         STA $27         ; Queue menu exit
         STZ $26         ; Next: Fade-out
         LDA #$05        ; Origin: Timer
         STA $0205       ; Set exit reason
         STA $B4         ; Disable this fn
C302F8:  RTS

; Load text string into tilemap
C302F9:  STY $E7         ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $E9         ; Set src HB
C302FF:  LDX $00         ; Dst index: 0
         TXY             ; Src index: 0
         REP #$20        ; 16-bit A
         LDA [$E7]       ; Tilemap ptr
         STA $EB         ; Set dst LBs
         INC $E7         ; Src adr +1
         INC $E7         ; Src adr +1
         SEP #$20        ; 8-bit A
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set dst HB
C30312:  LDA [$E7],Y     ; Text character
         BEQ C30325      ; Exit if <end>
         PHY             ; Save src index
         TXY             ; Dst index
         STA [$EB],Y     ; Add char to map
         INX             ; Map index +1
         TXY             ; Move it to Y
         LDA $29         ; Palette, etc.
         STA [$EB],Y     ; Set attributes
         INX             ; Dst index +1
         PLY             ; Src index
         INY             ; Src index +1
         BRA C30312      ; Load next char
C30325:  RTS

; Load and adjust window tile numbers, define attributes
C30326:  STY $E7         ; Save attributes
         LDX $00         ; Index: 0
         REP #$20        ; 16-bit A
C3032C:  LDA.L C3044E,X  ; Tile number
         CLC             ; Prepare ADC
         ADC $E7         ; Add attributes
         STA $7E9F19,X   ; Save in RAM
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0038      ; Done 28 tiles?
         BNE C3032C      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Prepare to and draw a menu window
C30341:  LDA #$C3        ; Bank: C3
         STA $E9         ; Set src HB
C30345:  STY $E7         ; Set src LBs
         LDX $00         ; ...
         TXY             ; Index: 0
         REP #$20        ; 16-bit A
         LDA [$E7],Y     ; Tilemap ptr
         STA $EB         ; Set position
         INY             ; Index +1
         INY             ; Index +1
         LDA [$E7],Y     ; Window size
         STA $E0         ; Memorize it
         SEP #$20        ; 8-bit A
         STA $E2         ; ...
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set ptr HB
         LDX $00         ; Clear X
         TXY             ; Clear Y...
         SEP #$10        ; 8-bit X, Y
         LDX $E0         ; Inner width
         LDY $E1         ; Inner height
         REP #$10        ; 16-bit X, Y
         STX $EF         ; Set 16b width
         STY $F1         ; Set 16b height
         REP #$20        ; 16-bit A
         JSR C30375      ; Draw window
         SEP #$20        ; 8-bit A
         RTS

; Draw a menu window
C30375:  JSR C303A3      ; Draw top row
         LDX $00         ; Inner row: 1st
         LDY #$0040      ; Skipped rows: 1
         STY $F3         ; Init map index
C3037F:  PHX             ; Save row number
         TXA             ; Move it to A
         AND #$0003      ; Get pattern row
         ASL A           ; Double it
         TAX             ; Index it
         JSR (C3039B,X)  ; Draw inner row
         LDA $F3         ; Tilemap index
         CLC             ; Prepare ADC
         ADC #$0040      ; Go 1 row down
         STA $F3         ; Save changes
         TAY             ; Index it
         PLX             ; Row number
         INX             ; Row number +1
         CPX $F1         ; At last row?
         BNE C3037F      ; Loop if not
         JMP C303BB      ; Draw last row

; Jump table for the above
C3039B:  dw C303D1       ; Pattern row 1 of 4
         dw C303DB       ; Pattern row 2 of 4
         dw C303E8       ; Pattern row 3 of 4
         dw C303F5       ; Pattern row 4 of 4

; Draw window's upper row
C303A3:  LDY $00         ; Map index: 0
         JSR C30408      ; Define pattern
         LDA $7E9F49     ; NW corner tile
         STA $E3         ; Set first tile
         LDA $7E9F4B     ; NE corner tile
         STA $E5         ; Set final tile
         LDX #$0020      ; Base tile index
         STX $E0         ; Memorize it
         BRA C30428      ; Draw top row

; Draw window's lower row
C303BB:  JSR C30408      ; Define pattern
         LDA $7E9F4D     ; SW corner tile
         STA $E3         ; Set first tile
         LDA $7E9F4F     ; SE corner tile
         STA $E5         ; Set final tile
         LDX #$0024      ; Base tile index
         STX $E0         ; Memorize it
         BRA C30428      ; Draw bottom row

; Draw inner window row, pattern part 1 of 4
C303D1:  JSR C30402      ; Define pattern
         JSR C3040E      ; Get side tiles
         STZ $E0         ; Base tile index
         BRA C30428      ; Draw inner row

; Draw inner window row, pattern part 2 of 4
C303DB:  JSR C30402      ; Define pattern
         JSR C3041B      ; Get side tiles
         LDX #$0008      ; Base tile index
         STX $E0         ; Memorize it
         BRA C30428      ; Draw inner row

; Draw inner window row, pattern part 3 of 4
C303E8:  JSR C30402      ; Define pattern
         JSR C3040E      ; Get side tiles
         LDX #$0010      ; Base tile index
         STX $E0         ; Memorize it
         BRA C30428      ; Draw inner row

; Draw inner window row, pattern part 4 of 4
C303F5:  JSR C30402      ; Define pattern
         JSR C3041B      ; Get side tiles
         LDX #$0018      ; Base tile index
         STX $E0         ; Memorize it
         BRA C30428      ; Draw inner row

; Set pattern width for inner window tiles
C30402:  LDX #$0003      ; Tiles: 4
         STX $F5         ; Set pattern width
         RTS

; Set pattern width for top or bottom window border
C30408:  LDX #$0001      ; Tiles: 2
         STX $F5         ; Set pattern width
         RTS

; Get window side tiles for odd-numbered pattern row
C3040E:  LDA $7E9F41     ; Left border A
         STA $E3         ; Set first tile
         LDA $7E9F43     ; Right border A
         STA $E5         ; Set final tile
         RTS

; Get window side tiles for even-numbered pattern row
C3041B:  LDA $7E9F45     ; Left border B
         STA $E3         ; Set first tile
         LDA $7E9F47     ; Right border B
         STA $E5         ; Set final tile
         RTS

; Draw a row of window tiles
C30428:  LDX $00         ; Inner col: 1st
         LDA $E3         ; Leftmost tile
         STA [$EB],Y     ; Add to tilemap
         INY             ; Map index +1
         INY             ; Map index +1
C30430:  PHX             ; Save column
         TXA             ; Move it to A
         AND $F5         ; Stay in pattern
         ASL A           ; Double it
         CLC             ; ...
         ADC $E0         ; Add base index
         TAX             ; Index sum
         LDA $7E9F19,X   ; Inner tile
         PLX             ; Column number
         CPX $EF         ; At last one?
         BEQ C30449      ; Branch if so
         STA [$EB],Y     ; Add tile to map
         INY             ; Map index +1
         INY             ; Map index +1
         INX             ; Column +1
         BRA C30430      ; Do next tile
C30449:  LDA $E5         ; Rightmost tile
         STA [$EB],Y     ; Add to tilemap
         RTS

; Window tile numbers
C3044E:  dw $0180        ; Inner part 1,1
         dw $0181        ; Inner part 1,2
         dw $0182        ; Inner part 1,3
         dw $0183        ; Inner part 1,4
         dw $0184        ; Inner part 2,1
         dw $0185        ; Inner part 2,2
         dw $0186        ; Inner part 2,3
         dw $0187        ; Inner part 2,4
         dw $0188        ; Inner part 3,1
         dw $0189        ; Inner part 3,2
         dw $018A        ; Inner part 3,3
         dw $018B        ; Inner part 3,4
         dw $018C        ; Inner part 4,1
         dw $018D        ; Inner part 4,2
         dw $018E        ; Inner part 4,3
         dw $018F        ; Inner part 4,4
         dw $0191        ; Upper border A
         dw $0192        ; Upper border B
         dw $0199        ; Lower border A
         dw $019A        ; Lower border B
         dw $0194        ; Left border A
         dw $0195        ; Right border A
         dw $0196        ; Left border B
         dw $0197        ; Right border B
         dw $0190        ; NW corner
         dw $0193        ; NE corner
         dw $0198        ; SW corner
         dw $019B        ; SE corner

; Draw 3 digits (16-bit number)
C30486:  LDY #$0005      ; Digits: 5
         STY $E0         ; Set counter
         LDY #$0002      ; Skipped: 2
         BRA C304C7      ; Draw text

; Draw 4 digits
C30490:  LDY #$0005      ; Digits: 5
         STY $E0         ; Set counter
         LDY #$0001      ; Skipped: 1
         BRA C304C7      ; Draw text

; Draw 5 digits
C3049A:  LDY #$0005      ; Digits: 5
         STY $E0         ; Set counter
         LDY $00         ; Skipped: 0
         BRA C304C7      ; Draw text

; Draw 8 digits
C304A3:  LDY #$0008      ; Digits: 8
         STY $E0         ; Set counter
         LDY $00         ; Skipped: 0
         BRA C304C7      ; Draw text

; Draw 7 digits
C304AC:  LDY #$0008      ; Digits: 8
         STY $E0         ; Set counter
         LDY #$0001      ; Skipped: 1
         BRA C304C7      ; Draw text

; Draw 2 digits
C304B6:  LDY #$0003      ; Digits: 3
         STY $E0         ; Set counter
         LDY #$0001      ; Skipped: 1
         BRA C304C7      ; Draw text

; Draw 3 digits (8-bit number)
C304C0:  LDY #$0003      ; Digits: 3
         STY $E0         ; Set counter
         LDY $00         ; Skipped: 0
C304C7:  STX $EB         ; Set dst LBs
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set dst HB
         TYX             ; Digit index
         LDY $00         ; Map index: 0
C304D0:  LDA $F7,X       ; Digit char
         STA [$EB],Y     ; Add to tilemap
         INY             ; Map index +1
         LDA $29         ; Palette, etc.
         STA [$EB],Y     ; Set attributes
         INY             ; Map index +1
         INX             ; Digit index +1
         CPX $E0         ; More digits?
         BNE C304D0      ; Loop if so
         RTS

; Convert 8-bit number into text, blank leading zeroes
C304E0:  JSR C304F9      ; Turn into text
         LDY $00         ; 1st: Hundreds
         LDX #$0002      ; Digits left: 2
C304E8:  LDA $00F7,Y     ; Digit char
         CMP.B #!num0    ; Zero?
         BNE C304F8      ; Exit if not
         LDA #$FF        ; Space char
         STA $00F7,Y     ; Replace digit
         INY             ; Point to next
         DEX             ; One less left
         BNE C304E8      ; Loop till last
C304F8:  RTS

; Convert 8-bit number into text, retain leading zeroes
C304F9:  STA $E0         ; Save number
         LDA #$03        ; Digits: 3
         STA $E4         ; Set counter
         LDY $00         ; RAM index: 0
         TYX             ; ROM index: 0
C30502:  STZ $E1         ; Digit: 0
         LDA.L C3052B,X  ; Power of 10
         INX             ; ROM index +1
         STA $E3         ; Save power
C3050B:  LDA $E0         ; Revised number
         SEC             ; Prepare SBC
         SBC $E3         ; Deduct power
         BCC C30518      ; Branch if < 0
         STA $E0         ; Save changes
         INC $E1         ; Digit +1
         BRA C3050B      ; Loop
C30518:  CLC             ; ...
         ADC $ED         ; ...
         STA $F3         ; ...
         LDA $E1         ; Digit
         CLC             ; Prepare ADC
         ADC.B #!num0    ; Turn into text
         STA $00F7,Y     ; Set digit char
         INY             ; Point to next
         DEC $E4         ; One less left
         BNE C30502      ; Loop till last
         RTS

; Powers of ten for the above
C3052B:  db $64          ; 100
         db $0A          ; 10
         db $01          ; 1

; Convert 16-bit number into text, blank leading zeroes
C3052E:  LDA #$05        ; Digits: 5
         STA $E0         ; Set counter
         LDY $00         ; RAM index: 0
         TYX             ; ROM index: 0
C30535:  REP #$20        ; 16-bit A
         LDA.L C30578,X  ; Power of 10
         INX             ; ROM index +1
         INX             ; ROM index +1
         STA $ED         ; Save power
         STZ $EB         ; Digit: 0
C30541:  SEC             ; Prepare SBC
         LDA $F3         ; Revised number
         SBC $ED         ; Deduct power
         BCC C3054E      ; Branch if < 0
         STA $F3         ; Save changes
         INC $EB         ; Digit +1
         BRA C30541      ; Loop

; Fork: Convert digit into text
C3054E:  CLC             ; ...
         ADC $ED         ; ...
         STA $F3         ; ...
         SEP #$20        ; 8-bit A
         LDA $EB         ; Digit
         CLC             ; ...
         ADC.B #!num0    ; Turn into text
         STA $00F7,Y     ; Set digit char
         INY             ; RAM index +1
         DEC $E0         ; One less digit
         BNE C30535      ; Loop till last

; Fork: Blank leading zeroes
C30562:  LDY $00         ; Index: 0
         LDX #$0004      ; Digits: 4
C30567:  LDA $00F7,Y     ; Digit char
         CMP.B #!num0    ; Zero?
         BNE C30577      ; Exit if not
         LDA #$FF        ; Space char
         STA $00F7,Y     ; Replace digit
         INY             ; Point to next
         DEX             ; One less left
         BNE C30567      ; Loop till last
C30577:  RTS

; Powers of ten for the above
C30578:  dw $2710        ; 10000
         dw $03E8        ; 1000
         dw $0064        ; 100
         dw $000A        ; 10
         dw $0001        ; 1

; Convert 24-bit number into text, blank leading zeroes
C30582:  STZ $F4         ; Number HB: 0
         LDA #$08        ; Digits: 8
         STA $E0         ; Set counter
         LDY $00         ; RAM index: 0
         TYX             ; ROM index: 0
C3058B:  REP #$20        ; 16-bit A
         STZ $EB         ; Digit: 0
C3058F:  SEC             ; Prepare SBC
         LDA $F1         ; Number LBs
         SBC.L C305DE,X  ; Deduct power's
         STA $F1         ; Save changes
         LDA $F3         ; Number HBs
         SBC.L C305EE,X  ; Deduct power's
         STA $F3         ; Save changes
         BCC C305A6      ; Branch if < 0
         INC $EB         ; Digit +1
         BRA C3058F      ; Loop

; Fork: Cancel subtraction and convert digit
C305A6:  LDA $F1         ; Number LBs
         CLC             ; ...
         ADC.L C305DE,X  ; Reverse SBC
         STA $F1         ; Save changes
         LDA $F3         ; Number HBs
         ADC.L C305EE,X  ; Reverse SBC
         STA $F3         ; Save changes
         SEP #$20        ; 8-bit A
         LDA $EB         ; Digit
         CLC             ; Prepare ADC
         ADC.B #!num0    ; Turn into text
         STA $00F7,Y     ; Set digit char
         INY             ; RAM index +1
         INX             ; ROM index +1
         INX             ; ROM index +1
         DEC $E0         ; One less digit
         BNE C3058B      ; Loop till last

; Fork: Blank leading zeroes
C305C8:  LDY $00         ; Index: 0
         LDX #$0007      ; Digits: 7
C305CD:  LDA $00F7,Y     ; Digit char
         CMP.B #!num0    ; Zero?
         BNE C305DD      ; Exit if not
         LDA #$FF        ; Space char
         STA $00F7,Y     ; Replace digit
         INY             ; Point to next
         DEX             ; One less left
         BNE C305CD      ; Loop till last
C305DD:  RTS

; Powers of ten, low bytes
C305DE:  dw $9680        ; 10000000
         dw $4240        ; 1000000
         dw $86A0        ; 100000
         dw $2710        ; 10000
         dw $03E8        ; 1000
         dw $0064        ; 100
         dw $000A        ; 10
         dw $0001        ; 1

; Powers of ten, high bytes
C305EE:  dw $0098        ; 10000000
         dw $000F        ; 1000000
         dw $0001        ; 100000
         dw $0000        ; 10000
         dw $0000        ; 1000
         dw $0000        ; 100
         dw $0000        ; 10
         dw $0000        ; 1

; Load navigation parameters for menu area
C305FE:  LDA #$C3        ; Bank: C3
         STA $ED         ; Set src HB
C30602:  STY $EB         ; Set src LBs
         LDY $00         ; Index: 0
         LDA [$EB],Y     ; Wrap flags
         STA $59         ; Save in RAM
         INY             ; Index +1
         REP #$20        ; 16-bit A
         STZ $51         ; See C3/06D5...
         LDA [$EB],Y     ; Initial spot
         STA $4D         ; Set cursor's
         INY             ; Index +1
         INY             ; Index +1
         LDA [$EB],Y     ; Rows, columns
         STA $53         ; Set boundaries
         STZ $4F         ; List col/row: 1
         SEP #$20        ; 8-bit A
         RTS

; Target party's leader
C3061E:  TDC             ; Clear A
         TAY             ; Member: 1st
C30620:  TYA             ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA $85,X       ; Empty slot?
         BNE C3062F      ; Exit if not
         INC $4E         ; Cursor row +1
         INY             ; Member slot +1
         CPY #$0004      ; Done all 4?
         BNE C30620      ; Loop if not
C3062F:  RTS

; Set address to table of cursor coordinates
C30630:  STY $E7         ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $E9         ; Set src HB
         RTS

; Position cursor in party area of Lineup menu
C30637:  JSR C30630      ; Set source
         JSR C30650      ; Set list slot
         JMP C306C5      ; Set coords

; Position cursor in unscrollable area
C30640:  JSR C30630      ; Set source
C30643:  JSR C30677      ; Set list slot
         BRA C306C5      ; Set coords

; Position cursor in scrollable list
C30648:  JSR C30630      ; Set source
         JSR C3069E      ; Set list slot
         BRA C306C5      ; Set coords

; Set cursor's slot position in party area of Lineup menu
C30650:  PHB             ; Save DB
         LDA #$00        ; Clear A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
C30655:  LDA $004212     ; PPU status
         AND #$40        ; H-Blank?
         BEQ C30655      ; Loop if not
         LDA $54         ; Number of rows
         STA $211B       ; Set matrix A LB
         STZ $211B       ; Clear HB
         LDA $4D         ; Cursor column
         STA $211C       ; Set matrix B
         STA $211C       ; ...
         LDA $2134       ; Product LB
         CLC             ; Prepare ADC
         ADC $4E         ; Add cursor row
         STA $4B         ; Set cursor slot
         PLB             ; Restore DB
         RTS

; Set cursor's slot position in unscrollable area
C30677:  PHB             ; Save DB
         LDA #$00        ; Clear A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
C3067C:  LDA $004212     ; PPU status
         AND #$40        ; H-Blank?
         BEQ C3067C      ; Loop if not
         LDA $53         ; Column count
         STA $211B       ; Set matrix A LB
         STZ $211B       ; Clear HB
         LDA $4E         ; Cursor row
         STA $211C       ; Set matrix B
         STA $211C       ; ...
         LDA $2134       ; Product LB
         CLC             ; Prepare ADC
         ADC $4D         ; Add cursor col
         STA $4B         ; Set cursor slot
         PLB             ; Restore DB
         RTS

; Set cursor's slot position in scrollable list
C3069E:  PHB             ; Save DB
         LDA #$00        ; Clear A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
C306A3:  LDA $004212     ; PPU status
         AND #$40        ; H-Blank?
         BEQ C306A3      ; Loop if not
         LDA $53         ; Column count
         STA $211B       ; Set matrix A LB
         STZ $211B       ; Clear HB
         LDA $50         ; List row
         STA $211C       ; Set matrix B
         STA $211C       ; ...
         LDA $2134       ; Product LB
         CLC             ; Prepare ADC
         ADC $4F         ; Add list column
         STA $4B         ; Set cursor slot
         PLB             ; Restore DB
         RTS

; Set cursor's position in pixels
C306C5:  PHB             ; Save DB
         LDA #$00        ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         LDA $53         ; Column count
         DEC A           ; Adjust value
         CMP $4D         ; In range now?
         BCS C306DD      ; Branch if so

; Fork: Invalid column (unused)
C306D1:  LDA $53         ; ...
         DEC A           ; ...
         SEC             ; Prepare SBC
         SBC $51         ; Minus 0...
         STA $E0         ; Use col qty -1
         STA $E2         ; Use last column
         BRA C306E5      ; Validate row

; Fork: Valid column
C306DD:  LDA $53         ; Column count
         STA $E0         ; Memorize it
         LDA $4D         ; Cursor column
         STA $E2         ; Memorize it

; Fork: Validate row
C306E5:  LDA $54         ; Number of rows
         DEC A           ; Adjust value
         CMP $4E         ; In range now?
         BCS C306F6      ; Branch if so

; Fork: Invalid row (unused)
C306EC:  LDA $54         ; ...
         DEC A           ; ...
         SEC             ; Prepare SBC
         SBC $52         ; Minus 0...
         STA $E1         ; Force last row
         BRA C306FA      ; Skip 2 lines

; Fork: Valid row
C306F6:  LDA $4E         ; Cursor row
         STA $E1         ; Memorize it
C306FA:  LDA $004212     ; PPU status
         AND #$40        ; H-Blank?
         BEQ C306FA      ; Loop if not
         LDA $E0         ; Number of columns
         STA $211B       ; Set matrix A LB
         STZ $211B       ; Clear HB
         LDA $E1         ; Cursor row
         STA $211C       ; Set matrix B
         STA $211C       ; ...
         LDA $2134       ; Product LB
         CLC             ; Prepare ADC
         ADC $E2         ; Add column
         ASL A           ; Double it
         XBA             ; Switch to HB
         LDA $00         ; Clear it
         XBA             ; Switch to LB
         TAY             ; Index it
         LDA [$E7],Y     ; X position
         STA $55         ; Set cursor's
         STZ $56         ; Clear HB
         INY             ; Index +1
         LDA [$E7],Y     ; Y position
         STA $57         ; Set cursor's
         STZ $58         ; Clear HB
         PLB             ; Restore DB
         RTS

; Handle D-Pad for unscrollable list
C3072D:  LDA $0B         ; Semi-auto keys
         BIT #$08        ; Pushing up?
         BEQ C30750      ; Branch if not
         LDA $4E         ; On top row?
         BNE C30748      ; Go up if not
         LDA $59         ; Wrap flags
         AND #$01        ; No V-Wrap?
         BNE C307AF      ; Exit if so
         LDA $54         ; Bottom row
         DEC A           ; Adjust value
         STA $4E         ; Set cursor row
         JSR C30EA3      ; Sound: Cursor
         JMP C307AF      ; Exit

; Fork: Move cursor up
C30748:  DEC $4E         ; Cursor row -1
         JSR C30EA3      ; Sound: Cursor
         JMP C307AF      ; Exit

; Fork: Handle down
C30750:  LDA $0B         ; Semi-auto keys
         BIT #$04        ; Pushing down?
         BEQ C30773      ; Branch if not
         LDA $54         ; Bottom row
         DEC A           ; Adjust value
         CMP $4E         ; Cursor's there?
         BNE C3076B      ; Go down if not
         LDA $59         ; Wrap flags
         AND #$01        ; No V-Wrap?
         BNE C307AF      ; Exit if so
         STZ $4E         ; Cursor row: 1
         JSR C30EA3      ; Sound: Cursor
         JMP C307AF      ; Exit

; Fork: Move cursor down
C3076B:  INC $4E         ; Cursor row +1
         JSR C30EA3      ; Sound: Cursor
         JMP C307AF      ; Exit

; Fork: Handle left
C30773:  LDA $0B         ; Semi-auto keys
         BIT #$02        ; Pushing left?
         BEQ C30792      ; Branch if not
         LDA $4D         ; On first column?
         BNE C3078B      ; Go left if not
         LDA $59         ; H-Wrap disabled?
         BMI C307AF      ; Exit if so
         LDA $53         ; Last column
         DEC A           ; Adjust value
         STA $4D         ; Set cursor column
         JSR C30EA3      ; Sound: Cursor
         BRA C307AF      ; Exit

; Fork: Move cursor left
C3078B:  DEC $4D         ; Cursor column -1
         JSR C30EA3      ; Sound: Cursor
         BRA C307AF      ; Exit

; Fork: Handle right
C30792:  LDA $0B         ; Semi-auto keys
         BIT #$01        ; Pushing right?
         BEQ C307AF      ; Exit if not
         LDA $53         ; Last column
         DEC A           ; Adjust value
         CMP $4D         ; Cursor's there?
         BNE C307AA      ; Go right if not
         LDA $59         ; H-Wrap disabled?
         BMI C307AF      ; Exit if so
         STZ $4D         ; Cursor column: 1
         JSR C30EA3      ; Sound: Cursor
         BRA C307AF      ; Exit

; Fork: Move cursor right
C307AA:  INC $4D         ; Cursor column +1
         JSR C30EA3      ; Sound: Cursor
C307AF:  RTS

; Queue movable cursor's OAM function
C307B0:  LDA #$01        ; Min slot: 8
         LDY #C307B8     ; C3/07B8
         JMP C31173      ; Queue OAM fn

; Update movable cursor's sprite
C307B8:  TAX             ; Index mode
         JMP (C307BC,X)  ; Handle mode

; Jump table for the above
C307BC:  dw C307C0       ; Initialize cursor
         dw C307DC       ; Sustain cursor

; Mode 0: Initialize cursor
C307C0:  LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         LDA #C3088D     ; Anim table ptr
         STA $32C9,X     ; Set sprite's
         SEP #$20        ; 8-bit A
         LDA #$C3        ; Bank: C3
         STA $35CA,X     ; Set ptr HB
         JSR C31206      ; Set pose timer
         INC $3649,X     ; Mode +1
         LDA #$01        ; Pans with BG1
         STA $364A,X     ; Set sprite flags

; Mode 1: Sustain cursor
C307DC:  LDA $46         ; Menu flags
         AND #$06        ; Remove cursors?
         BEQ C307FD      ; Delete if so
         LDA $45         ; Menu flags
         BIT #$04        ; Hide cursor?
         BEQ C307FB      ; Exit if so
         LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         LDA $55         ; Cursor's X
         STA $33CA,X     ; Set sprite's
         LDA $57         ; Cursor's Y
         STA $344A,X     ; Set sprite's
         SEP #$20        ; ...
         JSR C31221      ; Define OAM
C307FB:  SEC             ; Set to requeue
         RTS             ; Exit
C307FD:  CLC             ; Set to dequeue
         RTS

; Update blinking cursor marking prior choice
C307FF:  TAX             ; Index mode
         JMP (C30803,X)  ; Handle mode

; Jump table for the above
C30803:  dw C3080B       ; Initialize cursor
         dw C3082B       ; Sustain cursor V1
         dw C3080B       ; Initialize cursor
         dw C30867       ; Sustain cursor V2

; Mode 0 or 2: Initialize cursor
C3080B:  LDX $2D         ; Queue index
         LDA #$01        ; Blinkers V1: On
         TSB $46         ; Set menu flag
         REP #$20        ; 16-bit A
         LDA #C30896     ; Anim table ptr
         STA $32C9,X     ; Set sprite's
         SEP #$20        ; 8-bit A
         LDA #$C3        ; Bank: C3
         STA $35CA,X     ; Set ptr HB
         JSR C31206      ; Set pose timer
         LDA #$01        ; Pans with BG1
         STA $364A,X     ; Set sprite flags
         INC $3649,X     ; Mode +1

; Mode 1: Sustain cursor not in party area of Lineup menu
C3082B:  LDA $46         ; Menu flags
         BIT #$01        ; Remove blinkers?
         BEQ C30865      ; Delete if so
         LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         LDA $41         ; List V-Speed
         EOR #$FFFF      ; Invert it
         INC A           ; Add 1
         CLC             ; Prepare ADC
         ADC $344A,X     ; Add cursor's Y
         STA $344A,X     ; Set cursor's Y
         SEP #$20        ; 8-bit A
         LDA $46         ; Menu flags
         AND #$C0        ; Scrollable list?
         BEQ C30860      ; Display if not

; Fork: Item menu
C3084A:  LDA $28         ; Blinker's slot
         STA $E1         ; Memorize it
         INC A           ; Get next slot
         STA $E0         ; Memorize it
         LDA $4A         ; Top onscreen slot
         CLC             ; Prepare ADC
         ADC #$09        ; Get bottom slot
         CMP $E1         ; Blinker's below?
         BCC C30863      ; Blank if so
         LDA $4A         ; Top onscreen slot
         CMP $E0         ; Blinker's above?
         BCS C30863      ; Blank if so
C30860:  JSR C31221      ; Define OAM
C30863:  SEC             ; Set to requeue
         RTS             ; Exit
C30865:  CLC             ; Set to dequeue
         RTS

; Mode 3: Sustain cursor in party area of Lineup menu
C30867:  LDA $46         ; Menu flags
         BIT #$01        ; Remove blinkers?
         BEQ C30865      ; Delete if so
         LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         LDA $97         ; Always 0...
         EOR #$FFFF      ; Invert it
         INC A           ; Add 1
         CLC             ; Prepare ADC
         ADC $33CA,X     ; Add cursor's X
         STA $33CA,X     ; Set cursor's X
         SEP #$20        ; 8-bit A
         LDY $33CA,X     ; Cursor's X
         CPY #$0100      ; Past east edge?
         BCS C3088B      ; Blank if so
         JSR C31221      ; Define OAM
C3088B:  SEC             ; Set to requeue
         RTS

; Animation table for main cursor
C3088D:  dw C30890       ; Sprite 1
         db $FE          ; Freeze

; OAM for hand cursor
C30890:  db $01          ; Tiles: 1
         dw $0080        ; 16x16, X+0, Y+0
         dw $3E00        ; Tile 0, pal 7, prio 3

; OAM for blanking cursor
C30895:  db $00          ; Tiles: 0

; Animation table for blinking cursor
C30896:  dw C30890       ; Show cursor
         db $02          ; Frames: 2
         dw C30895       ; Hide cursor
         db $02          ; Frames: 2
         dw C30890       ; Bogus...
         db $FF          ; Loop

; Create a blinking cursor by every portrait
C3089F:  TDC             ; Clear A
         TAX             ; Member: 1st
C308A1:  LDA $85,X       ; Nobody here?
         BEQ C308C9      ; Skip if so
         PHX             ; Save index
         LDA #$01        ; Min slot: 8
         LDY #C308D1     ; C3/08D1
         JSR C31173      ; Queue OAM fn
         TXY             ; Queue index
         PLX             ; Member index
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         LDA $85,X       ; X position
         STA $33CA,Y     ; Set cursor's
         LDA $86,X       ; Y position
         STA $344A,Y     ; Set cursor's
         TDC             ; Clear A
         STA $33CB,Y     ; ...
         STA $344B,Y     ; ...
         LDA #$00        ; ...
         PHA             ; Put on stack
         PLB             ; Set DB to 0
C308C9:  INX             ; Char index +1
         INX             ; Char index +1
         CPX #$0008      ; Done 4 chars?
         BNE C308A1      ; Loop if not
         RTS

; Update blinking cursor not marking a prior choice
C308D1:  TAX             ; Index mode
         JMP (C308D5,X)  ; Handle mode

; Jump table for the above
C308D5:  dw C308D9       ; Initialize cursor
         dw C308F9       ; Sustain cursor

; Mode 0: Initialize cursor
C308D9:  LDX $2D         ; Queue index
         LDA #$08        ; Blinkers V2: On
         TSB $46         ; Set menu flag
         REP #$20        ; 16-bit A
         LDA #C30896     ; Anim table ptr
         STA $32C9,X     ; Set sprite's
         SEP #$20        ; 8-bit A
         LDA #$C3        ; Bank: C3
         STA $35CA,X     ; Set ptr HB
         JSR C31206      ; Set pose timer
         INC $3649,X     ; Mode +1
         LDA #$01        ; Pans with BG1
         STA $364A,X     ; Set sprite flags

; Mode 1: Sustain cursor
C308F9:  LDA $46         ; Menu flags
         BIT #$08        ; Remove blinkers?
         BEQ C30906      ; Delete if so
         LDX $2D         ; Queue index
         JSR C31221      ; Define OAM
         SEC             ; Set to requeue
         RTS             ; Exit
C30906:  CLC             ; Set to dequeue
         RTS

; Update scrollbar animation index
C30908:  LDA #$C0        ; Flashing: 2-ways
         TSB $46         ; Initialize index
         LDA $4A         ; At top of list?
         BNE C30914      ; Branch if not
         LDA #$40        ; Flashing: Down
         TRB $46         ; Update index
C30914:  LDA $4A         ; Scroll position
         CMP $5C         ; At very bottom?
         BNE C3091E      ; Exit if not
         LDA #$80        ; Flashing: Up
         TRB $46         ; Update index
C3091E:  RTS

; Create a scrollbar on right side of screen
C3091F:  LDA #$03        ; Min slot: 24
         LDY #C30947     ; C3/0947
         JSR C31173      ; Queue OAM fn
         REP #$20        ; 16-bit A
         LDA #$00E8      ; X: 232
         STA $7E33CA,X   ; Set sprite's
         SEP #$20        ; 8-bit A
         RTS

; Create a scrollbar in middle of screen
C30933:  LDA #$03        ; Min slot: 24
         LDY #C30947     ; C3/0947
         JSR C31173      ; Queue OAM fn
         REP #$20        ; 16-bit A
         LDA #$0078      ; X: 120
         STA $7E33CA,X   ; Set sprite's
         SEP #$20        ; 8-bit A
         RTS

; Update scrollbar
C30947:  TAX             ; Index mode
         JMP (C3094B,X)  ; Handle mode

; Jump table for the above
C3094B:  dw C3094F       ; Initialize scrollbar
         dw C3096A       ; Sustain scrollbar

; Mode 0: Initialize scrollbar
C3094F:  LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         LDA #C309E3     ; C3/09E3
         STA $32C9,X     ; Init anim ptr
         SEP #$20        ; 8-bit A
         LDA #$C3        ; Bank: C3
         STA $35CA,X     ; Set ptr HB
         INC $3649,X     ; Mode +1
         JSR C31206      ; Set pose timer
         LDA #$C0        ; Flash: Both ways
         TSB $46         ; Init anim index

; Mode 1: Sustain scrollbar
C3096A:  LDA $46         ; Menu flags
         AND #$C0        ; Hide scrollbar?
         BEQ C309D9      ; Delete if so
         LDX $2D         ; Queue index
         JSR C30908      ; Set anim index
C30975:  LDA $004212     ; PPU status
         AND #$40        ; H-Blank?
         BEQ C30975      ; Loop if not
         LDA $354A,X     ; V-Speed LB
         STA $00211B     ; Set matrix A LB
         LDA $354B,X     ; V-Speed HB
         STA $00211B     ; Set matrix A HB
         LDA $4A         ; Scroll position
         STA $00211C     ; Set matrix B
         STA $00211C     ; ...
         LDA $4A         ; Scroll position
         BMI C309AA      ; Branch if 128+
         TDC             ; Clear A
         LDA $002135     ; Product MB
         REP #$21        ; 16-bit A; C-
         ADC $34CA,X     ; Add base Y
         STA $344A,X     ; Set bar's Y
         SEP #$20        ; 8-bit A
         BRA C309BD      ; Skip 128+ case
C309AA:  TDC             ; Clear A
         LDA $002135     ; Product MB
         REP #$21        ; 16-bit A; C-
         ADC #$0070      ; Add 112
         CLC             ; ...
         ADC $34CA,X     ; Add base Y
         STA $344A,X     ; Set bar's Y
         SEP #$20        ; 8-bit A
C309BD:  TDC             ; Clear A
         LDA $46         ; Menu flags
         AND #$C0        ; Anim index
         LSR A           ; Put in b5-b6
         LSR A           ; Put in b4-b5
         LSR A           ; Put in b3-b4
         LSR A           ; Put in b2-b3
         LSR A           ; Put in b1-b2
         TXY             ; Queue index
         TAX             ; Anim index
         REP #$20        ; 16-bit A
         LDA.L C309DB,X  ; Anim pointer
         STA $32C9,Y     ; Set sprite's
         SEP #$20        ; ...
         JSR C31221      ; Define OAM
         SEC             ; Set to requeue
         RTS             ; Exit
C309D9:  CLC             ; Set to dequeue
         RTS

; Pointers to scrollbar animation tables
C309DB:  dw C309E3       ; Bogus...
         dw C309EC       ; Flashing up
         dw C309F5       ; Flashing down
         dw C309E3       ; Flashing both ways

; Animation table for scrollbar flashing both ways
C309E3:  dw C309FE       ; Flash neither
         db $10          ; Frames: 16
         dw C30A07       ; Flash both
         db $10          ; Frames: 16
         dw C309FE       ; Bogus...
         db $FF          ; Loop

; Animation table for scrollbar pointing up
C309EC:  dw C309FE       ; Flash neither
         db $10          ; Frames: 16
         dw C30A10       ; Flash highest
         db $10          ; Frames: 16
         dw C309FE       ; Bogus...
         db $FF          ; Loop

; Animation table for scrollbar pointing down
C309F5:  dw C309FE       ; Flash neither
         db $10          ; Frames: 16
         dw C30A19       ; Flash lowest
         db $10          ; Frames: 16
         dw C309FE       ; Bogus...
         db $FF          ; Loop

; OAM for non-flashing scrollbar
C309FE:  db $02          ; Tiles: 2
         dw $0000,$3E02  ; ^: White
         dw $0800,$BE02  ; v: White

; OAM for scrollbar flashing both ways
C30A07:  db $02          ; Tiles: 2
         dw $0000,$3E12  ; ^: Black
         dw $0800,$BE12  ; v: Black

; OAM for scrollbar pointing up
C30A10:  db $02          ; Tiles: 2
         dw $0000,$3E12  ; ^: Black
         dw $0800,$BE02  ; v: White

; OAM for scrollbar pointing down
C30A19:  db $02          ; Tiles: 2
         dw $0000,$3E02  ; ^: White
         dw $0800,$BE12  ; v: Black

; Create portrait for member 1
C30A22:  LDA #$03        ; Min slot: 24
         LDY #C30B12     ; C3/0B12
         JSR C31173      ; Queue OAM fn
         TXA             ; Queue index
         STA $60         ; Set sprite's
         PHB             ; Save DB
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         LDY $00         ; Member slot: 1
         JSR C30AF1      ; Set base X loc
         LDY $00         ; Face slot: 1
         JSR C30ACC      ; Load anim ptr
         REP #$20        ; 16-bit A
         LDA #$0015      ; Base Y: 21
         STA $344A,X     ; Set sprite's
         SEP #$20        ; 8-bit A
         JSR C31206      ; Set pose timer
         PLB             ; Restore DB
         RTS

; Create portrait for member 2
C30A4B:  LDA #$03        ; Min slot: 24
         LDY #C30B12     ; C3/0B12
         JSR C31173      ; Queue OAM fn
         TXA             ; Queue index
         STA $61         ; Set sprite's
         PHB             ; Save DB
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         LDY #$0001      ; Member slot: 2
         JSR C30AF1      ; Set base X loc
         LDY #$0001      ; Face slot: 2
         JSR C30ACC      ; Load anim ptr
         REP #$20        ; 16-bit A
         LDA #$0045      ; Base Y: 69
         STA $344A,X     ; Set sprite's
         SEP #$20        ; 8-bit A
         JSR C31206      ; Set pose timer
         PLB             ; Restore DB
         RTS

; Create portrait for member 3
C30A76:  LDA #$03        ; Min slot: 24
         LDY #C30B12     ; C3/0B12
         JSR C31173      ; Queue OAM fn
         TXA             ; Queue index
         STA $62         ; Set sprite's
         PHB             ; Save DB
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         LDY #$0002      ; Member slot: 3
         JSR C30AF1      ; Set base X loc
         LDY #$0002      ; Face slot: 3
         JSR C30ACC      ; Load anim ptr
         REP #$20        ; 16-bit A
         LDA #$0075      ; Base Y: 117
         STA $344A,X     ; Set sprite's
         SEP #$20        ; 8-bit A
         JSR C31206      ; Set pose timer
         PLB             ; Restore DB
         RTS

; Create portrait for member 4
C30AA1:  LDA #$03        ; Min slot: 24
         LDY #C30B12     ; C3/0B12
         JSR C31173      ; Queue OAM fn
         TXA             ; Queue index
         STA $63         ; Set sprite's
         PHB             ; Save DB
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         LDY #$0003      ; Member slot: 4
         JSR C30AF1      ; Set base X loc
         LDY #$0003      ; Face slot: 4
         JSR C30ACC      ; Load anim ptr
         REP #$20        ; 16-bit A
         LDA #$00A5      ; Base Y: 165
         STA $344A,X     ; Set sprite's
         SEP #$20        ; 8-bit A
         JSR C31206      ; Set pose timer
         PLB             ; Restore DB
         RTS

; Load pointer to animation table for portrait
C30ACC:  PHX             ; Save index
         PHX             ; Save index
         TYX             ; Member slot
         LDA $75,X       ; Party info
         AND #$18        ; Roster slot
         LSR A           ; Put in b2-b3
         LSR A           ; Put in b1-b2
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C30AE9,X  ; Anim table ptr
         PLY             ; Queue index
         STA $32C9,Y     ; Set ptr LBs
         SEP #$20        ; 8-bit A
         LDA #$C3        ; Bank: C3
         STA $35CA,Y     ; Set ptr HB
         PLX             ; Queue index
         RTS

; Pointers to portrait animation tables
C30AE9:  dw C30B8C       ; Portrait A
         dw C30BC4       ; Portrait B
         dw C30BFC       ; Portrait C
         dw C30C34       ; Portrait D

; Set portrait's base X position based on actor's row
C30AF1:  PHX             ; Queue index
         TYX             ; Member slot
         LDA #$02        ; Portrait bit
         BIT $45         ; Ignore row?
         BNE C30AFF      ; Branch if so
         LDA $75,X       ; Party info
         BIT #$20        ; In back row?
         BEQ C30B06      ; Branch if not
C30AFF:  REP #$20        ; 16-bit A
         LDA #$001A      ; Base X: 26
         BRA C30B0B      ; Skip 2 lines
C30B06:  REP #$20        ; 16-bit A
         LDA #$000E      ; Base X: 15
C30B0B:  PLX             ; Queue index
         STA $33CA,X     ; Set sprite's X
         SEP #$20        ; 8-bit A
         RTS

; Update actor portrait
C30B12:  TAX             ; Index mode
         JMP (C30B16,X)  ; Handle mode

; Jump table for the above
C30B16:  dw C30B20       ; Set to pan with BG1
         dw C30B2A       ; Sustain portrait
         dw C30B38       ; Set to shift right
         dw C30B4C       ; Set to shift left
         dw C30B5E       ; Shift left or right

; Mode 0: Set to pan with BG1
C30B20:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         LDA #$01        ; Pans with BG1
         STA $364A,X     ; Set sprite flags

; Mode 1: Sustain portrait
C30B2A:  LDX $2D         ; Queue index
         LDA $35C9,X     ; Hide portrait?
         BMI C30B36      ; Delete if so
         JSR C31221      ; Define OAM
         SEC             ; Set to requeue
         RTS             ; Exit
C30B36:  CLC             ; Set to dequeue
         RTS

; Mode 2: Set to shift right
C30B38:  LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         LDA #$0001      ; H-Speed: 1
         STA $34CA,X     ; Set sprite's
         LDA #$000C      ; Frames: 12
         STA $3349,X     ; Set shift timer
         SEP #$20        ; 8-bit A
         BRA C30B5E      ; Shift once

; Mode 3: Set to shift left
C30B4C:  LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         LDA #$FFFF      ; H-Speed: -1
         STA $34CA,X     ; Set sprite's
         LDA #$000C      ; Frames: 12
         STA $3349,X     ; Set shift timer
         SEP #$20        ; 8-bit A

; Mode 4: Shift left or right
C30B5E:  LDX $2D         ; Queue index
         LDA #$04        ; Mode: 4
         STA $3649,X     ; Set sprite's
         REP #$20        ; 16-bit A
         LDA $3349,X     ; Timer expired?
         BEQ C30B80      ; Freeze if so
         LDA $34CA,X     ; H-Speed
         CLC             ; Prepare ADC
         ADC $33CA,X     ; Add base X
         STA $33CA,X     ; Set sprite's
         DEC $3349,X     ; Timer -1
         SEP #$20        ; ...
         JSR C31221      ; Define OAM
         SEC             ; Set to requeue
         RTS

; Fork: Set to stop moving
C30B80:  SEP #$20        ; 8-bit A
         LDA #$01        ; Mode: 1
         STA $3649,X     ; Set sprite's
         JSR C31221      ; Define OAM
         SEC             ; Set to requeue
         RTS

; Animation table for portrait A
C30B8C:  dw C30B8F       ; Show portrait
         db $FE          ; Freeze

; OAM for portrait A
C30B8F:  db $0D          ; Tiles: 13
         dw $0080,$2060  ; Tile 1
         dw $0090,$2062  ; Tile 2
         dw $1080,$2064  ; Tile 3
         dw $1090,$2066  ; Tile 4
         dw $0020,$2068  ; Tile 5
         dw $0820,$2069  ; Tile 6
         dw $1020,$206A  ; Tile 7
         dw $1820,$206B  ; Tile 8
         dw $2020,$206C  ; Tile 9
         dw $2000,$206D  ; Tile 10
         dw $2008,$206E  ; Tile 11
         dw $2010,$206F  ; Tile 12
         dw $2018,$2078  ; Tile 13

; Animation table for portrait B
C30BC4:  dw C30BC7       ; Show portrait
         db $FE          ; Freeze

; OAM for portrait B
C30BC7:  db $0D          ; Tiles: 13
         dw $0080,$2280  ; Tile 1
         dw $0090,$2282  ; Tile 2
         dw $1080,$2284  ; Tile 3
         dw $1090,$2286  ; Tile 4
         dw $0020,$2288  ; Tile 5
         dw $0820,$2289  ; Tile 6
         dw $1020,$228A  ; Tile 7
         dw $1820,$228B  ; Tile 8
         dw $2020,$228C  ; Tile 9
         dw $2000,$228D  ; Tile 10
         dw $2008,$228E  ; Tile 11
         dw $2010,$228F  ; Tile 12
         dw $2018,$2298  ; Tile 13

; Animation table for portrait C
C30BFC:  dw C30BFF       ; Show portrait
         db $FE          ; Freeze

; OAM for portrait C
C30BFF:  db $0D          ; Tiles: 13
         dw $0080,$24A0  ; Tile 1
         dw $0090,$24A2  ; Tile 2
         dw $1080,$24A4  ; Tile 3
         dw $1090,$24A6  ; Tile 4
         dw $0020,$24A8  ; Tile 5
         dw $0820,$24A9  ; Tile 6
         dw $1020,$24AA  ; Tile 7
         dw $1820,$24AB  ; Tile 8
         dw $2020,$24AC  ; Tile 9
         dw $2000,$24AD  ; Tile 10
         dw $2008,$24AE  ; Tile 11
         dw $2010,$24AF  ; Tile 12
         dw $2018,$24B8  ; Tile 13

; Animation table for portrait D
C30C34:  dw C30C37       ; Show portrait
         db $FE          ; Freeze

; OAM for portrait D
C30C37:  db $0D          ; Tiles: 13
         dw $0080,$26C0  ; Tile 1
         dw $0090,$26C2  ; Tile 2
         dw $1080,$26C4  ; Tile 3
         dw $1090,$26C6  ; Tile 4
         dw $0020,$26C8  ; Tile 5
         dw $0820,$26C9  ; Tile 6
         dw $1020,$26CA  ; Tile 7
         dw $1820,$26CB  ; Tile 8
         dw $2020,$26CC  ; Tile 9
         dw $2000,$26CD  ; Tile 10
         dw $2008,$26CE  ; Tile 11
         dw $2010,$26CF  ; Tile 12
         dw $2018,$26D8  ; Tile 13

; Draw member's level, HP, and MP
C30C6C:  STX $EF         ; Pos tbl ptr LBs
         LDA #$C3        ; Bank: C3
         STA $F1         ; Set ptr HB
         LDX $67         ; Actor address
         LDA $0008,X     ; Level
         JSR C304E0      ; Turn into text
         REP #$20        ; 16-bit A
         LDA [$EF]       ; Tilemap ptr
         TAX             ; Move it to X
         SEP #$20        ; 8-bit A
         JSR C304B6      ; Draw level
         LDX $67         ; Actor address
         LDA $000B,X     ; Max HP LB
         STA $F3         ; Memorize it
         LDA $000C,X     ; Max HP HB
         STA $F4         ; Memorize it
         JSR C30D65      ; Add gear bonus
         JSR C30D92      ; Cap at 9999
         JSR C3052E      ; Turn into text
         LDY #$0004      ; Map ptr index
         JSR C30D21      ; Draw max HP
         LDY $67         ; Actor address
         JSR C32B9A      ; Truncate HP
         LDA $0009,Y     ; HP LB
         STA $F3         ; Memorize it
         LDA $000A,Y     ; HP HB
         STA $F4         ; Memorize it
         JSR C3052E      ; Turn into text
         LDY #$0002      ; Map ptr index
         JSR C30D21      ; Draw HP
         JSR C30D2B      ; Can use magic?
         BCC C30CEF      ; Hide MP if not
         LDX $67         ; Actor address
         LDA $000F,X     ; Max MP LB
         STA $F3         ; Memorize it
         LDA $0010,X     ; Max MP HB
         STA $F4         ; Memorize it
         JSR C30D65      ; Add gear bonus
         JSR C30D9F      ; Cap at 999
         JSR C3052E      ; Turn into text
         LDY #$0008      ; Map ptr index
         JSR C30D21      ; Draw max MP
         LDY $67         ; Actor address
         JSR C32BBC      ; Truncate MP
         LDA $000D,Y     ; MP LB
         STA $F3         ; Memorize it
         LDA $000E,Y     ; MP HB
         STA $F4         ; Memorize it
         JSR C3052E      ; Turn into text
         LDY #$0006      ; Map ptr index
         JMP C30D21      ; Draw MP

; Fork: Hide MP
C30CEF:  LDX #$9E8B      ; 7E/9E8B
         STX $2181       ; Set WRAM LBs
         REP #$20        ; 16-bit A
         LDY #$0006      ; Point to MP ptr
         LDA [$EF],Y     ; Tilemap ptr
         SEC             ; Prepare SBC
         SBC #$0006      ; Point to "MP"
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         LDX #$000C      ; Letters: 12
         LDA #$FF        ; Space char
C30D0B:  STA $2180       ; Add to string
         DEX             ; One less left
         BNE C30D0B      ; Loop till last
         STZ $2180       ; End string
         LDY #$9E89      ; 7E/9E89
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         JSR C302FF      ; Draw 12 spaces
         RTS

; Draw member's current or max HP or MP
C30D21:  REP #$20        ; 16-bit A
         LDA [$EF],Y     ; Tilemap ptr
         TAX             ; Move it to X
         SEP #$20        ; 8-bit A
         JMP C30490      ; Draw 4 digits

; Determine whether actor can use magic
C30D2B:  LDA $1A69       ; Espers LB
         ORA $1A6A       ; Add byte 2
         ORA $1A6B       ; Add byte 3
         ORA $1A6C       ; Add byte 4
         BNE C30D63      ; OK if got any
         LDX $67         ; Actor's address
         TDC             ; Clear A
         LDA $0000,X     ; Actor
         CMP #$0C        ; Gogo?
         BEQ C30D63      ; Allow if so
         BCS C30D61      ; Deny Umaro/guest
         STA $4202       ; Set multiplicand
         LDA #$36        ; Spell list length
         STA $4203       ; Set multiplier
         NOP
         NOP
         NOP
         LDY #$0036      ; Spells left: 54
         LDX $4216       ; Index product
C30D56:  LDA $1A6E,X     ; Spell mastery
         CMP #$FF        ; Fully learned?
         BEQ C30D63      ; Allow if so
         INX             ; Point to next
         DEY             ; One less left
         BNE C30D56      ; Loop till last
C30D61:  CLC             ; Access: No
         RTS             ; Exit
C30D63:  SEC             ; Access: Yes
         RTS

; Determine max HP or MP with gear bonus
C30D65:  REP #$20        ; 16-bit A
         LDA $F3         ; Max HP or MP
         AND #$3FFF      ; Clear flags
         STA $E7         ; Memorize value
         LDA $F3         ; Max HP or MP
         AND #$C000      ; Get bonus flags
         CLC             ; Prepare ROL
         ROL A           ; Put in b7 & C
         ROL A           ; Put in C & b0
         ROL A           ; Put in b0-b1
         ROL A           ; Put in b1-b2
         TAX             ; Index them
         LDA $E7         ; Max HP or MP
         JMP (C30D7E,X)  ; Apply bonus

; Jump table for the above
C30D7E:  dw C30D86       ; No bonus
         dw C30D88       ; HP or MP + 25%
         dw C30D89       ; HP or MP + 50%
         dw C30D87       ; HP or MP + 12.5%

; Boost max HP or MP based on entry point
C30D86:  TDC             ; Clear bonus
C30D87:  LSR A           ; Halve bonus
C30D88:  LSR A           ; Halve bonus
C30D89:  LSR A           ; Halve bonus
         CLC             ; Prepare ADC
         ADC $E7         ; Add max value
         STA $F3         ; Memorize sum
         SEP #$20        ; 8-bit A
         RTS

; Enforce HP cap
C30D92:  LDX $F3         ; Max HP
         CPX #$2710      ; Under 10000?
         BCC C30D9E      ; Exit if so
         LDX #$270F      ; Enforce 9999
         STX $F3         ; Save changes
C30D9E:  RTS

; Enforce MP cap
C30D9F:  LDX $F3         ; Max MP
         CPX #$03E8      ; Under 1000?
         BCC C30DAB      ; Exit if so
         LDX #$03E7      ; Enforce 999
         STX $F3         ; Save changes
C30DAB:  RTS

; Restore cursor position in inventory
C30DAC:  LDY $022F       ; Old list pos
         STY $4F         ; Set as current
         LDA $4F         ; List column
         STA $4D         ; Set as onscreen
         LDA $0231       ; Old scroll pos
         BRA C30E1E      ; Restore it, etc.

; Interchange cursor memory for swapped members
C30DBA:  TDC             ; Clear A
         LDA $4B         ; Chosen slot B
         ASL A           ; Double it
         TAX             ; Index it
         LDA $28         ; Chosen slot A
         ASL A           ; Double it
         TAY             ; Index it
         REP #$20        ; 16-bit A
         LDA $0236,X     ; B's Skills pos
         STA $E7         ; Memorize it
         LDA $0236,Y     ; A's Skills pos
         STA $0236,X     ; Set as B's
         LDA $E7         ; B's Skills pos
         STA $0236,Y     ; Set as A's
         LDA $023E,X     ; B's Magic pos
         STA $E7         ; Memorize it
         LDA $023E,Y     ; A's Magic pos
         STA $023E,X     ; Set as B's
         LDA $E7         ; B's Magic pos
         STA $023E,Y     ; Set as A's
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $4B         ; Chosen slot B
         TAX             ; Index it
         LDA $28         ; Chosen slot A
         TAY             ; Index it
         LDA $0246,X     ; B's Magic bar
         STA $E0         ; Memorize pos
         LDA $0246,Y     ; A's Magic bar
         STA $0246,X     ; Set as B's
         LDA $E0         ; B's Magic bar
         STA $0246,Y     ; Set as A's
         RTS

; Restore cursor position in Skills menu
C30DFF:  TDC             ; Clear A
         LDA $28         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         LDY $0236,X     ; Former position
         STY $4D         ; Set as current
         RTS

; Restore cursor position in Magic menu
C30E0A:  TDC             ; Clear A
         LDA $28         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         LDY $023E,X     ; Old list pos
         STY $4F         ; Set as current
         LDA $4F         ; List column
         STA $4D         ; Set as onscreen
         LDA $28         ; Member slot
         TAX             ; Index it
         LDA $0246,X     ; Old scroll pos
C30E1E:  STA $4A         ; Set as current
         LDA $50         ; List row
         SEC             ; Prepare SBC
         SBC $4A         ; Sub scroll pos
         STA $4E         ; Set onscreen row
         RTS

; Upload BG1 tilemaps A and B
C30E28:  LDY #$0000      ; $0000
         STY $2116       ; Set VRAM ptr
         LDY #$3849      ; 7E/3849
         STY $4302       ; Set src LBs
         BRA C30E88      ; Move data

; Upload BG1 tilemaps B and C
C30E36:  LDY #$0400      ; $0800
         STY $2116       ; Set VRAM ptr
         LDY #$4049      ; 7E/4049
         STY $4302       ; Set src LBs
         BRA C30E88      ; Move data

; Upload BG1 tilemaps C and D
C30E44:  LDY #$0800      ; $1000
         STY $2116       ; Set VRAM ptr
         LDY #$4849      ; 7E/4849
         STY $4302       ; Set src LBs
         BRA C30E88      ; Move data

; Upload BG2 tilemaps A and B
C30E52:  LDY #$1000      ; $2000
         STY $2116       ; Set VRAM ptr
         LDY #$5849      ; 7E/5849
         STY $4302       ; Set src LBs
         BRA C30E88      ; Move data

; Upload BG2 tilemaps C and D
C30E60:  LDY #$1800      ; $3000
         STY $2116       ; Set VRAM ptr
         LDY #$6849      ; 7E/6849
         STY $4302       ; Set src LBs
         BRA C30E88      ; Move data

; Upload BG3 tilemaps A and B
C30E6E:  LDY #$4000      ; $8000
         STY $2116       ; Set VRAM ptr
         LDY #$7849      ; 7E/7849
         STY $4302       ; Set src LBs
         BRA C30E88      ; Move data

; Upload BG3 tilemaps C and D
C30E7C:  LDY #$4800      ; $9000
         STY $2116       ; Set VRAM ptr
         LDY #$8849      ; 7E/8849
         STY $4302       ; Set src LBs
C30E88:  LDA #$01        ; 2Rx1B to PPU
         STA $4300       ; Set DMA mode
         LDA #$18        ; $2118
         STA $4301       ; To VRAM
         LDA #$7E        ; Bank: 7E
         STA $4304       ; Set src HB
         LDY #$1000      ; Bytes: 4096
         STY $4305       ; Set data size
         LDA #$01        ; Channel: 0
         STA $420B       ; Move data
         RTS

; Play cursor sound
C30EA3:  LDA $AE         ; Started sound
         CMP #$21        ; Cursor's?
         BEQ C30EB1      ; Exit if so
C30EA9:  LDA #$21        ; APU command
         STA $AE         ; Prevent repeat
         STA $002140     ; Set I/O port 0
C30EB1:  RTS

; Play click sound
C30EB2:  LDA #$20        ; APU command
         STA $002140     ; Set I/O port 0
         RTS

; Play save sound
C30EB9:  LDA #$23        ; APU command
         STA $002140     ; Set I/O port 0
         RTS

; Play buzzer sound
C30EC0:  LDA #$22        ; APU command
         STA $002140     ; Set I/O port 0
         RTS

; Play letter deletion sound
C30EC7:  LDA #$24        ; APU command
         STA $002140     ; Set I/O port 0
         RTS

; Play cash register sound
C30ECE:  LDA #$BF        ; Sound number
C30ED0:  STA $001301     ; Set I/O port 1
         LDA #$18        ; APU command
         STA $001300     ; Set I/O port 0
         LDA #$80        ; Volume specs
         STA $001302     ; Set I/O port 2
         JSL $C50004     ; Update ports
         RTS

; Play recovery sound
C30EE5:  LDA #$C5        ; Sound number
         BRA C30ED0      ; Set vol, etc.

; Set to upload BG1 tilemaps A and B
C30EE9:  LDY #$0000      ; $0000
         STY $14         ; Set VRAM ptr
         LDY #$3849      ; 7E/3849
         STY $16         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $18         ; Set src HB
         LDY #$1000      ; Bytes: 4096
         STY $12         ; Set data size
         RTS

; Set to upload BG1 tilemap A
C30EFD:  LDY #$0000      ; $0000
         STY $14         ; Set VRAM ptr
         LDY #$3849      ; 7E/3849
         STY $16         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $18         ; Set src HB
         LDY #$0800      ; Bytes: 2048
         STY $12         ; Set data size
         RTS

; Set to upload BG1 tilemap B
C30F11:  LDY #$0400      ; $0800
         STY $14         ; Set VRAM ptr
         LDY #$4049      ; 7E/4049
         STY $16         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $18         ; Set src HB
         LDY #$0800      ; Bytes: 2048
         STY $12         ; Set data size
         RTS

; Set to upload BG3 tilemaps A and B
C30F25:  LDY #$4000      ; $8000
         STY $14         ; Set VRAM ptr
         LDY #$7849      ; 7E/7849
         STY $16         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $18         ; Set src HB
         LDY #$1000      ; Bytes: 4096
         STY $12         ; Set data size
         RTS

; Set to upload BG3 tilemap A (version 1)
C30F39:  LDY #$4000      ; $8000
         STY $14         ; Set VRAM ptr
         LDY #$7849      ; 7E/7849
         STY $16         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $18         ; Set src HB
         LDY #$0800      ; Bytes: 2048
         STY $12         ; Set data size
         RTS

; Set to upload BG3 tilemap B (version 1)
C30F4D:  LDY #$4400      ; $8800
         STY $14         ; Set VRAM ptr
         LDY #$8049      ; 7E/8049
         STY $16         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $18         ; Set src HB
         LDY #$0800      ; Bytes: 2048
         STY $12         ; Set data size
         RTS

; Set to upload BG3 tilemap A (version 2)
C30F61:  LDY #$4000      ; $8000
         STY $1B         ; Set VRAM ptr
         LDY #$7849      ; 7E/7849
         STY $1D         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $1F         ; Set src HB
         LDY #$0800      ; Bytes: 2048
         STY $19         ; Set data size
         RTS

; Set to upload BG3 tilemap B (version 2)
C30F75:  LDY #$4400      ; $8800
         STY $1B         ; Set VRAM ptr
         LDY #$8049      ; 7E/8049
         STY $1D         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $1F         ; Set src HB
         LDY #$0800      ; Bytes: 2048
         STY $19         ; Set data size
         RTS

; Disable conditional upload during NMI
C30F89:  STZ $1B         ; Null dst LB
         STZ $1C         ; Null dst HB
         RTS

; Load specified palette (for ending)
C30F8E:  STA $ED         ; Set src HB
         STY $E7         ; Set dst LBs
         STX $EB         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set dst HB
         LDY $00         ; Index: 0
         REP #$20        ; 16-bit A
C30F9C:  LDA [$EB],Y     ; Load color
         STA [$E7],Y     ; Save in RAM
         INY             ; Index +1
         INY             ; Index +1
         CPY #$0020      ; Copied 16?
         BNE C30F9C      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Set to gradually convert one palette into another
C30FAA:  PHA             ; Save slowness
         STY $E7         ; Save dst LBs
         STX $EB         ; Save src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Save dst HB
         LDA #$00        ; Min slot: 0
         LDY #C30FDD     ; C3/0FDD
         JSR C31173      ; Queue fade fn
         PLA             ; Fade slowness
         STA $7E37CA,X   ; Put in queue
         LDA $E9         ; Dest HB
         STA $7E36C9,X   ; Put in queue
         LDA $ED         ; Source HB
         STA $7E36CA,X   ; Put in queue
         REP #$20        ; 16-bit A
         LDA $E7         ; Dest LBs
         STA $7E33C9,X   ; Put in queue
         LDA $EB         ; Source LBs
         STA $7E3449,X   ; Put in queue
         SEP #$20        ; 8-bit A
         RTS

; Gradually convert one palette into another
C30FDD:  TAX             ; Index mode
         JMP (C30FE1,X)  ; Handle mode

; Jump table for the above
C30FE1:  dw C30FE5       ; Initialize timer
         dw C30FF6       ; Modify palette

; Mode 0: Initialize timer
C30FE5:  LDX $2D         ; Queue index
         LDA #$1F        ; Frames: 31
         STA $3349,X     ; Set fade timer
         LDA $00         ; Clear A
         STA $334A,X     ; Timer HB: 0
         INC $3649,X     ; Mode +1
         SEC             ; Set to requeue
         RTS

; Mode 1: Modify palette
C30FF6:  LDX $2D         ; Queue index
         LDA $35C9,X     ; Delay over?
         BNE C31032      ; Exit if not
         LDA $37CA,X     ; Slowness
         STA $35C9,X     ; Set delay
         LDA $36C9,X     ; Dest HB
         STA $E2         ; Memorize it
         LDA $36CA,X     ; Source HB
         STA $E5         ; Memorize it
         REP #$20        ; 16-bit A
         LDA $33C9,X     ; Dest LBs
         STA $E0         ; Memorize them
         LDA $3449,X     ; Source LBs
         STA $E3         ; Memorize them
         LDA $3349,X     ; Fade timer
         STA $F1         ; Memorize it
         JSR C31037      ; Alter palette
         SEP #$20        ; 8-bit A
         LDX $002D       ; Queue index
         LDA $3349,X     ; Timer expired?
         BEQ C31030      ; Dequeue if so
         DEC $3349,X     ; Fade timer -1
         BNE C31032      ; Branch if > 0
C31030:  CLC             ; Set to dequeue
         RTS             ; Exit
C31032:  DEC $35C9,X     ; Fade delay -1
         SEC             ; Set to requeue
         RTS

; Partially convert one palette into another
C31037:  LDX #$0010      ; Colors: 16
         LDY $00         ; Color index: 0
C3103C:  LDA [$E0],Y     ; Actual color
         STA $E7         ; Memorize it
         LDA [$E3],Y     ; Target color
         STA $E9         ; Memorize it
         JSR C31051      ; Alter color
         LDA $E7         ; ...
         STA [$E0],Y     ; Save changes
         INY             ; Color index +1
         INY             ; Color index +1
         DEX             ; One less color
         BNE C3103C      ; Loop till last
         RTS

; Partially convert one color into another
C31051:  LDA $E7         ; Actual color
         AND #$001F      ; Get red
         STA $EB         ; Memorize it
         LDA $E9         ; Target color
         AND #$001F      ; Get red
         SEC             ; Prepare SBC
         SBC $EB         ; Both match?
         BEQ C3106E      ; Skip if so
         BCC C3106C      ; -1 if lesser
         CMP $F1         ; Diff < timer?
         BCC C3106E      ; Skip if so
         INC $EB         ; Red +1
         BRA C3106E      ; Skip a line
C3106C:  DEC $EB         ; Red -1

; Fork: Handle green
C3106E:  LDA $E7         ; Actual color
         AND #$03E0      ; Get green
         STA $ED         ; Memorize it
         LDA $E9         ; Target color
         AND #$03E0      ; Get green
         SEC             ; Prepare SBC
         SBC $ED         ; Both match?
         BEQ C3109B      ; Skip if so
         BCC C31093      ; -1 if lesser
         ASL A           ; x2
         ASL A           ; x4
         ASL A           ; x8
         XBA             ; Now 0-31
         CMP $F1         ; Diff < timer?
         BCC C3109B      ; Skip if so
         CLC             ; Prepare ADC
         LDA $ED         ; Actual green
         ADC #$0020      ; Green +1
         STA $ED         ; Save changes
         BRA C3109B      ; Do blue
C31093:  LDA $ED         ; Actual green
         SEC             ; Prepare SBC
         SBC #$0020      ; Green -1
         STA $ED         ; Save changes

; Fork: Handle blue
C3109B:  LDA $E7         ; Actual color
         AND #$7C00      ; Get blue
         STA $EF         ; Memorize it
         LDA $E9         ; Target color
         AND #$7C00      ; Get blue
         SEC             ; Prepare SBC
         SBC $EF         ; Both match?
         BEQ C310CB      ; Skip if so
         BCC C310C3      ; -1 if lesser
         SEP #$20        ; 8-bit A
         XBA             ; ÷256
         LSR A           ; ÷512
         LSR A           ; Now 0-31
         REP #$20        ; 16-bit A
         CMP $F1         ; Diff < timer?
         BCC C310CB      ; Skip if so
         CLC             ; Prepare ADC
         LDA $EF         ; Actual blue
         ADC #$0400      ; Blue +1
         STA $EF         ; Save changes
         BRA C310CB      ; Merge RGB
C310C3:  LDA $EF         ; Actual blue
         SEC             ; Prepare SBC
         SBC #$0400      ; Blue -1
         STA $EF         ; Save changes

; Fork: Merge RGB components
C310CB:  LDA $EB         ; Altered red
         ORA $ED         ; Add green
         ORA $EF         ; Add blue
         STA $E7         ; Uh...
         RTS

; White palette for an ending transition
C310D4:  dw $0000,$7FFF,$7FFF,$7FFF,$7FFF,$7FFF,$7FFF,$7FFF
         dw $7FFF,$7FFF,$7FFF,$7FFF,$7FFF,$7FFF,$7FFF,$7FFF

; Black palette for most ending transitions
C310F4:  dw $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
         dw $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000

; Reset OAM and animation queue
C31114:  LDX $00         ; Clear X
         STX $2D         ; Queue index: 0
         STX $2F         ; No use...
         REP #$20        ; 16-bit A
         JSR C3114E      ; Reset OAM
         SEP #$10        ; 8-bit X, Y
         LDX #$7E        ; Bank: 7E
         PHX             ; Put on stack
         PLB             ; Set DB to 7E
         LDX #$00        ; Queue slot: 1
C31127:  STZ $3249,X     ; Anim fn: None
         STZ $3649,X     ; Anim mode: 0
         STZ $35C9,X     ; Misc. specs: 0
         STZ $3749,X     ; OAM complements
         STZ $33C9,X     ; Fractional X: 0
         STZ $3449,X     ; Fractional Y: 0
         STZ $34C9,X     ; H-Speed: 0
         STZ $3549,X     ; V-Speed: 0
         INX             ; Index +1
         INX             ; Index +1
         CPX #$80        ; Done 64 slots?
         BNE C31127      ; Loop if not
         LDX #$00        ; Bank: 00
         PHX             ; Put on stack
         PLB             ; Set DB to 0
         SEP #$20        ; 8-bit A
         REP #$10        ; 16-bit X, Y
         RTS

; Reset OAM
C3114E:  LDX $00         ; Index: 0
C31150:  LDA #$E001      ; X=1, Y=224
         STA $0300,X     ; Put offscreen
         INX             ; Index +1
         INX             ; Index +1
         LDA #$0001      ; Tile num: 1
         STA $0300,X     ; Set attribs
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0200      ; Past Lo-OAM?
         BNE C31150      ; Loop if not
         LDY $00         ; Index: 0
         TYA             ; Clear A
C31168:  STA $0500,Y     ; Clear Hi-OAM
         INY             ; Index +1
         INY             ; Index +1
         CPY #$0020      ; Past Hi-OAM?
         BNE C31168      ; Loop if not
         RTS

; Queue animation function, include queue index
C31173:  TAX             ; Starting slot
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         TXA             ; Starting slot
         JSR C3118B      ; Queue anim fn
         SEP #$20        ; 8-bit A
         LDA #$00        ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         LDA $2D         ; Caller's index
         STA $7E374A,X   ; Put in queue
         INC $2F         ; No use...
         RTS

; Queue animation function
C3118B:  XBA             ; Switch to HB
         LDA #$00        ; Clear it
         XBA             ; Starting slot
         ASL A           ; x2
         ASL A           ; x4
         ASL A           ; x8
         ASL A           ; x16
         REP #$20        ; 16-bit A
         TAX             ; Index it
C31196:  LDA $3249,X     ; Empty slot?
         BNE C311A0      ; Skip if not
         TYA             ; Animation fn
         STA $3249,X     ; Put in queue
         RTS

; Fork: Try next slot
C311A0:  INX             ; Index +1
         INX             ; Index +1
         CPX #$0080      ; Past slot 64?
         BNE C31196      ; Loop if not
         DEX             ; Index -1
         DEX             ; Index -1
         TYA             ; Animation fn
         STA $3249,X     ; Put in queue
C311AD:  BRA C311AD      ; Freeze game...
         RTS             ; ...

; Process animation queue, hide inactive objects
C311B0:  PHB             ; Save DB
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         LDX #$0300      ; 7E/0300
         STX $0E         ; Set Lo-OAM ptr
         LDX #$0500      ; 7E/0500
         STX $10         ; Set Hi-OAM ptr
         LDA #$03        ; Tile: 1 of 4
         STA $33         ; Set Hi-OAM index
         STZ $34         ; Hi-OAM: 4x 8x8
         LDX #$0080      ; Objects: 128
         STX $31         ; Set space left
         LDX $00         ; Queue index: 0
         REP #$20        ; 16-bit A
C311CE:  LDA $3249,X     ; Animation fn
         BEQ C311F5      ; Skip if blank
         STX $2D         ; Set queue index
         PHX             ; Save index
         STA $2B         ; Set anim fn
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $3649,X     ; Anim mode
         ASL A           ; Double it
         JSR C31203      ; Run anim fn
         REP #$20        ; 16-bit A
         PLX             ; Queue index
         BCS C311F5      ; Branch if kept
         STZ $3249,X     ; Anim fn: None
         STZ $3649,X     ; Anim mode: 0
         STZ $35C9,X     ; Misc. specs: 0
         STZ $3749,X     ; OAM complements
         DEC $2F         ; No use...
C311F5:  INX             ; Index +1
         INX             ; Index +1
         CPX #$0080      ; Done 64 slots?
         BNE C311CE      ; Loop if not
         JSR C31338      ; Purge OAM
         SEP #$20        ; 8-bit A
         PLB             ; Restore DB
         RTS

; Execute queued animation function
C31203:  JMP ($002B)     ; Run anim fn

; Initialize M7 or object's pose number and timer
C31206:  TDC             ; Clear A
         STA $36C9,X     ; Pose: 1st
         REP #$20        ; 16-bit A
         LDA $32C9,X     ; Anim ptr LBs
         STA $EB         ; Set src LBs
         SEP #$20        ; 8-bit A
         LDA $35CA,X     ; Anim ptr HB
         STA $ED         ; Set src HB
         LDY #$0002      ; Skip pose ptr
         LDA [$EB],Y     ; Pose timer
         STA $36CA,X     ; Set sprite's
         RTS

; Handle object's pose timer, then define OAM
C31221:  JSR C31227      ; Pose timer -1
         JMP C31273      ; Define OAM

; Handle pose or Mode 7 timer
C31227:  LDX $2D         ; Queue index
         LDY $00         ; ...
         REP #$20        ; 16-bit A
         LDA $32C9,X     ; Anim ptr LBs
         STA $EB         ; Set src LBs
         SEP #$20        ; 8-bit A
         LDA $35CA,X     ; Anim ptr HB
         STA $ED         ; Set src HB

; Fork: Handle control codes
C31239:  LDA $36CA,X     ; Pose timer
         CMP #$FE        ; Infinite?
         BEQ C31262      ; Exit if so
         CMP #$FF        ; Loop point?
         BNE C3124C      ; Branch if not
         STZ $36C9,X     ; Pose: 1st
         JSR C31263      ; Set new timer
         BRA C31239      ; Repeat checks

; Fork: Check if expired
C3124C:  LDA $36CA,X     ; Timer expired?
         BNE C3125F      ; Branch if not
         LDA $36C9,X     ; Pose index
         CLC             ; ...
         ADC #$03        ; Point to next
         STA $36C9,X     ; Save changes
         JSR C31263      ; Set new timer
         BRA C31239      ; Repeat checks

; Fork: Decrease timer
C3125F:  DEC $36CA,X     ; Timer -1
C31262:  RTS

; Initialize pose or Mode 7 timer
C31263:  SEP #$10        ; 8-bit X, Y
         LDA $36C9,X     ; Pose index
         TAY             ; Index it
         INY             ; Skip ptr LB
         INY             ; Skip ptr HB
         LDA [$EB],Y     ; Pose timer
         STA $36CA,X     ; Set object's
         REP #$10        ; 16-bit X, Y
         RTS

; Define OAM for object's tiles
C31273:  SEP #$10        ; 8-bit X, Y
         LDA $36C9,X     ; Pose index
         TAY             ; Index it
         REP #$20        ; 16-bit A
         LDA [$EB],Y     ; Pose OAM ptr
         STA $E7         ; Set src LBs
         INY             ; ...
         INY             ; ...
         SEP #$20        ; 8-bit A
         LDA $35CA,X     ; OAM ptr HB
         STA $E9         ; Set src HB
         REP #$10        ; 16-bit X, Y
         LDY $00         ; Index: 0
         LDA $31         ; OAM's full?
         BEQ C312FB      ; Exit if so
         LDA [$E7],Y     ; Tile count
         STA $E6         ; Memorize it
         BEQ C312FB      ; Exit if none
         INY             ; Index +1

; Fork: Large tile (16x16)
C31297:  LDA [$E7],Y     ; Tile X & flag
         STA $E0         ; Memorize them
         BPL C312B0      ; Branch if 8x8
         TDC             ; Clear A
         LDA $33         ; Hi-OAM index
         TAX             ; Index it
         LDA.L C31334,X  ; Size flag
         CLC             ; Prepare ADC
         ADC $34         ; Add flag pack
         STA $34         ; Set flag pack
         STA ($10)       ; Put in Hi-OAM
         LDX $2D         ; Queue index
         BRA C312B4      ; Skip 2 lines

; Fork: Small tile (8x8)
C312B0:  LDA $34         ; OAM flag pack
         STA ($10)       ; Put in Hi-OAM
C312B4:  LDA $E0         ; Tile's X-Pos
         AND #$7F        ; Clear flag
         STA $E0         ; Save changes

; Fork: Pan with BG1
C312BA:  LDA $364A,X     ; Sprite flags
         BIT #$01        ; Pan with BG1?
         BEQ C312CE      ; Branch if not
         STZ $E1         ; Tile's X HB: 0
         REP #$20        ; 16-bit A
         LDA $E0         ; Tile's rel X
         SEC             ; Prepare SBC
         SBC $35         ; Deduct BG1 X-Pos
         STA $E0         ; Save changes
         SEP #$20        ; 8-bit A

; Fork: Define Lo-OAM, do next tile
C312CE:  JSR C312FC      ; Adjust attribs
         DEC $33         ; Hi-OAM index -1
         BPL C312DF      ; Branch if 0+
         LDA #$03        ; Tile: 1 of 4
         STA $33         ; Reset size index
         STZ $34         ; Hi-OAM: 4x 8x8
         REP #$20        ; 16-bit A
         INC $10         ; Hi-OAM ptr +1
C312DF:  REP #$20        ; 16-bit A
         LDA $E0         ; Tile coords
         STA ($0E)       ; Save in OAM
         INC $0E         ; Lo-OAM ptr +1
         INC $0E         ; Lo-OAM ptr +1
         LDA $E2         ; Tile num/attr
         STA ($0E)       ; Save in OAM
         INC $0E         ; Lo-OAM ptr +1
         INC $0E         ; Lo-OAM ptr +1
         SEP #$20        ; 8-bit A
         DEC $31         ; Space left -1
         BEQ C312FB      ; Exit if full
         DEC $E6         ; Tiles left -1
         BNE C31297      ; Loop till last
C312FB:  RTS

; Determine object tile's coordinates, load attributes
C312FC:  LDA $E0         ; Tile's rel X
         CLC             ; Prepare ADC
         ADC $33CA,X     ; Add object's X
         STA $E0         ; Save changes
         INY             ; Index +1
         LDA [$E7],Y     ; Tile's rel Y
         CLC             ; Prepare ADC
         ADC $344A,X     ; Add object's Y
         STA $E1         ; Memorize sum
         INY             ; Index +1
         LDA [$E7],Y     ; Tile num LSBs
         STA $E2         ; Memorize them
         INY             ; Index +1
         LDA $364A,X     ; Sprite flags
         BIT #$02        ; Mirror H-wise?
         BEQ C31320      ; Branch if not
         LDA [$E7],Y     ; Tile attributes
         ORA #$40        ; Add H-Flip
         BRA C31322      ; Skip a line
C31320:  LDA [$E7],Y     ; Tile attributes
C31322:  STA $E3         ; Memorize them
         LDA $3749,X     ; OAM complements
         BEQ C31332      ; Exit if none
         LDA $E3         ; Tile attributes
         AND #$F1        ; Clear palette
         ORA $3749,X     ; Add complements
         STA $E3         ; Save changes
C31332:  INY             ; Index +1
         RTS

; Hi-OAM complements
C31334:  db $80          ; Tile 4: Large
         db $20          ; Tile 3: Large
         db $08          ; Tile 2: Large
         db $02          ; Tile 1: Large

; Hide inactive tiles in OAM
C31338:  LDY $31         ; Unused tiles
         BEQ C3134C      ; Exit if none
         LDX #$01FC      ; Tile: Last
         LDA #$E001      ; X=1, Y=224
C31342:  STA $0300,X     ; Set position
         DEX             ; OAM index -1
         DEX             ; OAM index -1
         DEX             ; OAM index -1
         DEX             ; OAM index -1
         DEY             ; Tiles left -1
         BNE C31342      ; Loop till last
C3134C:  RTS

; Trigger NMI, decode joypads, etc.
C3134D:  JSR C31368      ; Trigger NMI
         LDA $46         ; Menu flags
         BIT #$20        ; Scroll list?
         BEQ C31359      ; Branch if not
         JSR C38105      ; Scroll BG1
C31359:  JSL C3A46E      ; Decode joypads
         LDA $20         ; Transition timer
         BEQ C31367      ; Exit if off
         TDC             ; Clear A
         TAY             ; Clear Y
         STY $08         ; No-autofire keys
         STY $0A         ; Semi-auto keys
C31367:  RTS

; Trigger NMI, allow cursor sound to repeat
C31368:  LDA #$81        ; Stop IRQ timers
         STA $4200       ; On: NMI, joypads
         STA $24         ; Mark NMI request
         CLI             ; Unmask IRQs
C31370:  LDA $24         ; Back from NMI?
         BNE C31370      ; Loop if not
         SEI             ; Mask IRQs
         LDA $44         ; Brightness
         STA $2100       ; Apply it now
         LDA $43         ; Queued HDMA
         STA $420C       ; Update channels
         LDA $B5         ; Mosaic settings
         STA $2106       ; Apply to screen
         STZ $AE         ; Allow SFX repeat
         RTS

; Handle NMI (menu, ending)
C31387:  PHP             ; ...
         REP #$30        ; 16-bit A, X, Y
         PHA             ; Save A
         PHX             ; Save X
         PHY             ; Save Y
         PHB             ; Save DB
         PHD             ; Save DP
         SEP #$20        ; 8-bit A
         LDA $4210       ; Clear NMI flag
         LDA #$00        ; Clear A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         LDX #$0000      ; Clear X
         PHX             ; Put on stack
         PLD             ; Set DP to 0
         LDA $24         ; Manual NMI?
         BEQ C313B1      ; Branch if not
         JSR C31412      ; Refresh screen
         REP #$20        ; 16-bit A
         INC $CF         ; Ending timer +1
         SEP #$20        ; 8-bit A
         LDY $20         ; Transition timer
         BEQ C313B1      ; Ignore if off
         DEY             ; Timer -1
         STY $20         ; Save changes
C313B1:  JSL $C00015     ; Event timers -1
         JSL C313C8      ; Play time +1
         INC $23         ; NMI count +1
         TDC             ; Clear A
         STA $24         ; Unmark manual NMI
         REP #$30        ; 16-bit A, X, Y
         PLD             ; Restore DP
         PLB             ; Restore DB
         PLY             ; Restore Y
         PLX             ; Restore X
         PLA             ; Restore A
         PLP             ; ...
         RTI

; Handle IRQ...
C313C7:  RTI

; Advance play time (NMI)
C313C8:  LDA $021E       ; Frames
         CMP #$3C        ; 60?
         BEQ C313D1      ; +1 sec if so
         BRA C313FC      ; +1 frame

; Fork: Seconds +1
C313D1:  STZ $021E       ; Frames = 0
         LDA $021D       ; Seconds
         CMP #$3B        ; 59?
         BEQ C313E0      ; +1 min if so
         INC $021D       ; +1 second
         BRA C313FC      ; +1 frame

; Fork: Minutes +1
C313E0:  STZ $021D       ; Seconds = 0
         LDA $021C       ; Minutes
         CMP #$3B        ; 59?
         BEQ C313EF      ; +1 hour if so
         INC $021C       ; +1 minute
         BRA C313FC      ; +1 frame

; Fork: Hours +1
C313EF:  STZ $021C       ; Minutes = 0
         LDA $021B       ; Hours
         CMP #$63        ; 99?
         BEQ C313FC      ; Branch if so
         INC $021B       ; +1 hour

; Fork: Frames +1
C313FC:  LDA $021B       ; Hours
         CMP #$63        ; 99?
         BNE C3140D      ; Branch if not
         LDA $021C       ; Minutes
         CMP #$3B        ; 59?
         BNE C3140D      ; Branch if not
         STZ $021D       ; Seconds = 0
C3140D:  INC $021E       ; +1 frame
         TDC             ; Clear A
         RTL

; Refresh screen (NMI)
C31412:  STZ $420C       ; Disable HDMA
         STZ $420B       ; Disable DMA...
         LDA $35         ; BG1 X-Pos LB
         STA $210D       ; Apply it now
         LDA $36         ; BG1 X-Pos HB
         STA $210D       ; Apply it now
         LDA $37         ; BG1 Y-Pos LB
         STA $210E       ; Apply it now
         LDA $38         ; BG1 Y-Pos HB
         STA $210E       ; Apply it now
         LDA $39         ; BG2 X-Pos LB
         STA $210F       ; Apply it now
         LDA $3A         ; BG2 X-Pos HB
         STA $210F       ; Apply it now
         LDA $3B         ; BG2 Y-Pos LB
         STA $2110       ; Apply it now
         LDA $3C         ; BG2 Y-Pos HB
         STA $2110       ; Apply it now
         LDA $3D         ; BG3 X-Pos LB
         STA $2111       ; Apply it now
         LDA $3E         ; BG3 X-Pos HB
         STA $2111       ; Apply it now
         LDA $3F         ; BG3 Y-Pos LB
         STA $2112       ; Apply it now
         LDA $40         ; BG3 Y-Pos HB
         STA $2112       ; Apply it now
         JSR C3D263      ; Refresh Mode 7
         JSR C31463      ; Refresh OAM
         JSR C314D2      ; Refresh CGRAM
         JSR C31488      ; Do VRAM DMA A
         JMP C314AC      ; Do VRAM DMA B

; Refresh OAM (NMI)
C31463:  LDX $00         ; $0000
         STX $2102       ; Set OAM address
         TXA             ; Bank: 00
         STA $4304       ; Set src HB
         LDA #$02        ; 1Rx2B to PPU
         STA $4300       ; Set DMA mode
         LDA #$04        ; $2104
         STA $4301       ; To OAM
         LDY #$0300      ; 00/0300
         STY $4302       ; Set src LBs
         LDY #$0220      ; Bytes: 544
         STY $4305       ; Set data size
         LDA #$01        ; Channel: 0
         STA $420B       ; Move data
         RTS

; Handle absolute VRAM transfer (NMI)
C31488:  LDY $14         ; Destination
         STY $2116       ; Set VRAM ptr
         LDA #$01        ; 2Rx1B to PPU
         STA $4300       ; Set DMA mode
         LDA #$18        ; $2118
         STA $4301       ; To VRAM
         LDY $16         ; Source LBs
         STY $4302       ; Set CH0's
         LDA $18         ; Source HB
         STA $4304       ; Set CH0's
         LDY $12         ; Number of bytes
         STY $4305       ; Set data size
         LDA #$01        ; Channel: 0
         STA $420B       ; Move data
         RTS

; Handle conditional VRAM transfer (NMI)
C314AC:  LDY $1B         ; Destination
         BEQ C314D1      ; Exit if none
         STY $2116       ; Set VRAM ptr
         LDA #$01        ; 2Rx1B to PPU
         STA $4300       ; Set DMA mode
         LDA #$18        ; $2118
         STA $4301       ; To VRAM
         LDY $1D         ; Source LBs
         STY $4302       ; Set CH0's
         LDA $1F         ; Source HB
         STA $4304       ; Set CH0's
         LDY $19         ; Number of bytes
         STY $4305       ; Set data size
         LDA #$01        ; Channel: 0
         STA $420B       ; Move data
C314D1:  RTS

; Refresh CGRAM (NMI)
C314D2:  LDA $45         ; Menu flags
         BIT #$01        ; Freeze CGRAM?
         BEQ C314FD      ; Exit if so
         LDA $00         ; CGRAM: $0000
         STA $2121       ; To BG color 0
         LDA #$02        ; 1Rx2B to PPU
         STA $4300       ; Set DMA mode
         LDA #$22        ; $2122
         STA $4301       ; To CGRAM
         LDY #$3049      ; 7E/3049
         STY $4302       ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $4304       ; Set src HB
         LDY #$0200      ; Bytes: 512
         STY $4305       ; Set data size
         LDA #$01        ; Channel: 0
         STA $420B       ; Move data
C314FD:  RTS

; Load save data on defeat
C314FE:  LDA $021F       ; File number
         BEQ C31514      ; Reset if none
         JSR C31566      ; Load save file
         JSR C319D1      ; Compute checksum
         JSR C319EB      ; Bad checksum?
         BEQ C31514      ; Reset game if so
         JSR C31595      ; Move timer data
         TDC             ; Reset game: No
         BRA C31518      ; Set aftereffect

; Fork: Reset game
C31514:  SEP #$20        ; ...
         LDA #$FF        ; Reset game: Yes
C31518:  STA $0205       ; Set aftereffect
         TDC             ; ...
         RTL

; Record game data
C3151D:  AND #$03        ; File number
         STA $307FF0     ; Set last altered
         STA $0224       ; Set last viewed
         PHA             ; Memorize slot
         LDY $021B       ; Hrs, mins played
         STY $1863       ; To SRAM block
         LDA $021D       ; Seconds played
         STA $1865       ; To SRAM block
         JSR C31586      ; Move timer data
         JSR C319D1      ; Compute checksum
         LDY $E7         ; File checksum
         STY $1FFE       ; To SRAM block
         TDC             ; Clear A
         PLA             ; File number
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C3155E,X  ; SRAM pointer
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDY $00         ; RAM index: 0
C3154D:  LDA $1600,Y     ; Game data
         STA $306000,X   ; Save in SRAM
         INX             ; SRAM index +1
         INY             ; RAM index +1
         CPY #$0A00      ; At $2000?
         BNE C3154D      ; Loop if not
         JMP C37083      ; Mark all files

; SRAM pointers
C3155E:  dw $0000        ; Bogus...
         dw $0000        ; Save slot 1
         dw $0A00        ; Save slot 2
         dw $1400        ; Save slot 3

; Load save file
C31566:  XBA             ; Get HB
         LDA $00         ; Clear it
         XBA             ; File number
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C3155E,X  ; SRAM pointer
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDY $00         ; RAM index: 0
C31577:  LDA $306000,X   ; Saved data
         STA $1600,Y     ; Copy to RAM
         INX             ; SRAM index +1
         INY             ; RAM index +1
         CPY #$0A00      ; At $2000?
         BNE C31577      ; Loop if not
         RTS

; Copy event timer data to save area
C31586:  TDC             ; Clear A
         TAX             ; Index: 0
C31588:  LDA $1188,X     ; Timer data
         STA $1FA8,X     ; Put in SRAM
         INX             ; Index +1
         CPX #$0018      ; At $11A0?
         BNE C31588      ; Loop if not
         RTS

; Restore saved event timer data
C31595:  TDC             ; Clear A
         TAX             ; Index: 0
C31597:  LDA $1FA8,X     ; Timer data
         STA $1188,X     ; Make active
         INX             ; Index +1
         CPX #$0018      ; At $1FC0?
         BNE C31597      ; Loop if not
         RTS

; Load navigation data for Save menu
C315A4:  LDY #C315B3     ; C3/15B3
         JMP C305FE      ; Load navig data

; Handle D-Pad for Save menu
C315AA:  JSR C3072D      ; Handle D-Pad
C315AD:  LDY #C315CE     ; C3/15CE
         JMP C30640      ; Relocate cursor

; Navigation data for Save menu
C315B3:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $03          ; 3 rows

; Load navigation data for Load menu
C315B8:  LDY #C315C7     ; C3/15C7
         JMP C305FE      ; Load navig data

; Handle D-Pad for Load menu
C315BE:  JSR C3072D      ; Handle D-Pad
C315C1:  LDY #C315CC     ; C3/15CC
         JMP C30640      ; Relocate cursor

; Navigation data for Load menu
C315C7:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $04          ; 4 rows

; Cursor positions for Save and Load menus
C315CC:  dw $1C08        ; New Game
C315CE:  dw $3C08        ; Save file 1
         dw $7408        ; Save file 2
         dw $AC08        ; Save file 3

; Load navigation data for save file confirmation
C315D4:  LDY #C315E3     ; C3/15E3
         JMP C305FE      ; Load navig data

; Handle D-Pad for save file confirmation
C315DA:  JSR C3072D      ; Handle D-Pad
C315DD:  LDY #C315E8     ; C3/15E8
         JMP C30640      ; Relocate cursor

; Navigation data for save file confirmation
C315E3:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $02          ; 2 rows

; Cursor positions for save file confirmation
C315E8:  dw $44BF        ; Yes
         dw $54BF        ; No

; Draw Save menu, load skins, list actor sprites
C315EC:  JSR C36A28      ; Clear BG2 map A
         JSR C31632      ; Handle files
         JSR C33A87      ; Load skin visuals
         LDY #C3189C     ; C3/189C
         JSR C30341      ; Draw top window
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDY #C31A78     ; Text pointer
         JSR C302F9      ; Draw "Save"
         JMP C31890      ; Upload tilemaps

; Draw Load menu, load skins, list actor sprites
C31608:  JSR C36A28      ; Clear BG2 map A
         STZ $1D4E       ; Skin: 1st; etc.
         JSR C36BBC      ; Reset skin colors
         JSR C33A87      ; Load skin visuals
         LDY #C3189C     ; C3/189C
         JSR C30341      ; Draw top window
         LDA $1D4E       ; Game options
         AND #$70        ; Reset skin, gauge
         STA $1D4E       ; Save changes
         JSR C31632      ; Handle files
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDY #C31A7F     ; Text pointer
         JSR C302F9      ; Draw "New Game"
         JMP C31890      ; Upload tilemaps

; Output all save files
C31632:  JSR C36C60      ; Load grayscale
         LDA #$20        ; Channel: 5
         TRB $43         ; Halt HDMA-5
         LDY #$0002      ; Y: 2
         STY $37         ; Set BG1 Y-Pos
         LDY $1D55       ; User font color
         STY $E7         ; Memorize it
         LDY #$7FFF      ; Color: White
         STY $1D55       ; Set user's font
         JSR C33F99      ; Put in palettes
         LDY $E7         ; Original color
         STY $1D55       ; Restore config
         LDA #$01        ; Gradient set: 1
         JSL $D4CA1D     ; Create gradient
         JSR C36A15      ; Clear BG1 map A
         JSR C36A3C      ; Clear BG3 map A
         JSR C36A46      ; Clear BG3 map C
         JSR C318AC      ; Move game's SRAM

; Fork: Load save file 1
C31663:  LDA #$01        ; File: 1
         STA $66         ; ...
         JSR C31566      ; Load save file
         JSR C36915      ; Move party info
         JSR C319D1      ; Compute checksum
         JSR C319EB      ; Test validity
         STY $91         ; Save checksum
         BEQ C31682      ; Branch if invalid
         JSR C36F61      ; List char sprites
         JSR C3171D      ; Draw file 1 text
         JSR C33AF5      ; Load skin colors
         BRA C31695      ; Handle file 2

; Fork: Blank file 1
C31682:  JSR C318C1      ; Restore skin 1
         JSR C36F61      ; Use blank party
         LDA #$20        ; Palette 0
         STA $29         ; Color: White
         LDY #C31A24     ; Text pointer
         JSR C302F9      ; Draw "Empty"
         JSR C33AF5      ; Load skin 1 pal

; Fork: Load save file 2
C31695:  LDA #$02        ; File: 2
         STA $66         ; ...
         JSR C31566      ; Load save file
         JSR C36915      ; Move party info
         JSR C319D1      ; Compute checksum
         JSR C319EB      ; Test validity
         STY $93         ; Save checksum
         BEQ C316B4      ; Branch if invalid
         JSR C36FB8      ; List char sprites
         JSR C317CA      ; Draw file 2 text
         JSR C33B09      ; Load skin colors
         BRA C316C7      ; Handle file 3

; Fork: Blank file 2
C316B4:  JSR C318C1      ; Restore skin 1
         JSR C36FB8      ; Use blank party
         LDA #$20        ; Palette 0
         STA $29         ; Color: White
         LDY #C31A2C     ; Text pointer
         JSR C302F9      ; Draw "Empty"
         JSR C33B09      ; Load skin 1 pal

; Fork: Load save file 3
C316C7:  LDA #$03        ; File: 3
         STA $66         ; ...
         JSR C31566      ; Load save file
         JSR C36915      ; Move party info
         JSR C319D1      ; Compute checksum
         JSR C319EB      ; Test validity
         STY $95         ; Save checksum
         BEQ C316E6      ; Branch if invalid
         JSR C36FDC      ; List char sprites
         JSR C3182D      ; Draw file 3 text
         JSR C33B1D      ; Load skin colors
         BRA C316F9      ; Draw all windows

; Fork: Blank file 3
C316E6:  JSR C318C1      ; Restore skin 1
         JSR C36FDC      ; Use blank party
         LDA #$20        ; Palette 0
         STA $29         ; Color: White
         LDY #C31A34     ; Text pointer
         JSR C302F9      ; Draw "Empty"
         JSR C33B1D      ; Load skin 1 pal

; Fork: Draw windows and upload skins
C316F9:  JSR C318C1      ; Restore SRAM
         JSR C33AA1      ; Upload skin A
         LDY #C318A0     ; C3/18A0
         JSR C30341      ; Draw window A
         JSR C33ABD      ; Upload skin B
         LDY #C318A4     ; C3/18A4
         JSR C30341      ; Draw window B
         JSR C33AD9      ; Upload skin C
         LDY #C318A8     ; C3/18A8
         JSR C30341      ; Draw window C
         LDY #$1C00      ; Palette: 7
         JMP C30326      ; Build skin map

; Draw all text for save file 1
C3171D:  LDA #$20        ; Palette 0
         STA $29         ; Color: White
         LDY #C31A51     ; Text pointer
         JSR C302F9      ; Draw ":"
         LDA $1863       ; Hours played
         JSR C304E0      ; Turn into text
         LDX #$7B0D      ; Text position
         JSR C304B6      ; Draw hours
         LDA $1864       ; Minutes played
         JSR C304F9      ; Turn into text
         LDX #$7B13      ; Text position
         JSR C304B6      ; Draw minutes
         JSR C3174D      ; Draw leader info
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         LDY #C31A3C     ; Text pointer
         JSR C302F9      ; Draw "Time"
         RTS

; Draw leader info for save file 1
C3174D:  TDC             ; Clear A
         TAX             ; 1st: Member 1
C3174F:  LDA $69,X       ; Actor in slot
         BMI C3177C      ; Skip if empty
         JSR C317BE      ; Get its address
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         LDY #C31A5D     ; Text pointer
         JSR C302F9      ; Draw "LV"
         LDA #$20        ; Palette 0
         STA $29         ; Color: White
         LDY #C31A6C     ; Text pointer
         JSR C302F9      ; Draw "/"
         LDY #$3A4F      ; Text position
         PHY             ; Set name's
         LDX #$7AFD      ; Text position
         PHX             ; Set max HP's
         LDX #$7AF3      ; Text position
         PHX             ; Set HP's
         LDX #$7A81      ; Text position
         PHX             ; Set level's
         BRA C3177F      ; Draw stats
C3177C:  INX             ; Member slot +1
         BRA C3174F      ; Try next member

; Draw leader's stats over save file
C3177F:  LDX $67         ; Actor's address
         LDA $0008,X     ; Level
         JSR C304E0      ; Turn into text
         PLX             ; Text position
         JSR C304B6      ; Draw 2 digits
         LDY $67         ; Actor's address
         JSR C32B9A      ; Truncate HP
         LDA $0009,Y     ; HP LB
         STA $F3         ; Memorize it
         LDA $000A,Y     ; HP HB
         STA $F4         ; Memorize it
         JSR C3052E      ; Turn into text
         PLX             ; Text position
         JSR C30490      ; Draw 4 digits
         LDX $67         ; Actor address
         LDA $000B,X     ; Max HP LB
         STA $F3         ; Memorize it
         LDA $000C,X     ; Max HP HB
         STA $F4         ; Memorize it
         JSR C30D65      ; Add gear bonus
         JSR C30D92      ; Cap at 9999
         JSR C3052E      ; Turn into text
         PLX             ; Text position
         JSR C30490      ; Draw 4 digits
         PLY             ; Text position
         JMP C334CF      ; Draw actor name

; Get member's SRAM block address
C317BE:  REP #$20        ; 16-bit A
         TXA             ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA $6D,X       ; SRAM address
         STA $67         ; Save for later
         SEP #$20        ; 8-bit A
         RTS

; Draw all text for save file 2
C317CA:  LDA #$20        ; Palette 0
         STA $29         ; Color: White
         LDY #C31A55     ; Text pointer
         JSR C302F9      ; Draw ":"
         LDA $1863       ; Hours played
         JSR C304E0      ; Turn into text
         LDX #$7CCD      ; Text position
         JSR C304B6      ; Draw 2 digits
         LDA $1864       ; Minutes played
         JSR C304F9      ; Turn into text
         LDX #$7CD3      ; Text position
         JSR C304B6      ; Draw 2 digits
         JSR C317FA      ; Draw leader info
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         LDY #C31A43     ; Text pointer
         JSR C302F9      ; Draw "Time"
         RTS

; Draw leader info for save file 2
C317FA:  TDC             ; Clear A
         TAX             ; 1st: Member 1
C317FC:  LDA $69,X       ; Actor in slot
         BMI C3182A      ; Skip if empty
         JSR C317BE      ; Get its address
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         LDY #C31A62     ; Text pointer
         JSR C302F9      ; Draw "LV"
         LDA #$20        ; Palette 0
         STA $29         ; Color: White
         LDY #C31A70     ; Text pointer
         JSR C302F9      ; Draw "/"
         LDY #$3C0F      ; Text position
         PHY             ; Set name's
         LDX #$7CBD      ; Text position
         PHX             ; Set max HP's
         LDX #$7CB3      ; Text position
         PHX             ; Set HP's
         LDX #$7C41      ; Text position
         PHX             ; Set level's
         JMP C3177F      ; Draw stats
C3182A:  INX             ; Member slot +1
         BRA C317FC      ; Try next member

; Draw all text for save file 3
C3182D:  LDA #$20        ; Palette 0
         STA $29         ; Color: White
         LDY #C31A59     ; Text pointer
         JSR C302F9      ; Draw ":"
         LDA $1863       ; Hours played
         JSR C304E0      ; Turn into text
         LDX #$7E8D      ; Text position
         JSR C304B6      ; Draw 2 digits
         LDA $1864       ; Minutes played
         JSR C304F9      ; Turn into text
         LDX #$7E93      ; Text position
         JSR C304B6      ; Draw 2 digits
         JSR C3185D      ; Draw leader info
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         LDY #C31A4A     ; Text pointer
         JSR C302F9      ; Draw "Time"
         RTS

; Draw leader info for save file 3
C3185D:  TDC             ; Clear A
         TAX             ; 1st: Member 1
C3185F:  LDA $69,X       ; Actor in slot
         BMI C3188D      ; Skip if empty
         JSR C317BE      ; Get its address
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         LDY #C31A67     ; Text pointer
         JSR C302F9      ; Draw "LV"
         LDA #$20        ; Palette 0
         STA $29         ; Color: White
         LDY #C31A74     ; Text pointer
         JSR C302F9      ; Draw "/"
         LDY #$3DCF      ; Text position
         PHY             ; Set name's
         LDX #$7E7D      ; Text position
         PHX             ; Set max HP's
         LDX #$7E73      ; Text position
         PHX             ; Set HP's
         LDX #$7E01      ; Text position
         PHX             ; Set level's
         JMP C3177F      ; Draw stats
C3188D:  INX             ; Member slot +1
         BRA C3185F      ; Try next member

; Upload tilemaps for Save or Load menu
C31890:  JSR C30E28      ; Upload BG1 A+B
         JSR C30E52      ; Upload BG2 A+B
         JSR C30E6E      ; Upload BG3 A+B
         JMP C30E7C      ; Upload BG3 C+D

; Window layout for Save and Load menus
C3189C:  dw $58CB,$021C  ; 30x4 at $58CB (Top window)
C318A0:  dw $59CB,$051C  ; 30x7 at $59CB (File A)
C318A4:  dw $5B8B,$051C  ; 30x7 at $5B8B (File B)
C318A8:  dw $5D4B,$051C  ; 30x7 at $5D4B (File C)

; Back up SRAM block
C318AC:  LDY #$AC8D      ; 7E/AC8D
         STY $2181       ; Set WRAM LBs
         LDX $00         ; Index: 0
C318B4:  LDA $1600,X     ; SRAM data
         STA $2180       ; Put in WRAM
         INX             ; Index +1
         CPX #$0A00      ; At $2000?
         BNE C318B4      ; Loop if not
         RTS

; Restore SRAM block
C318C1:  LDX $00         ; Index: 0
C318C3:  LDA $7EAC8D,X   ; Data backup
         STA $1600,X     ; Restore it
         INX             ; Index +1
         CPX #$0A00      ; At 7E/B68D?
         BNE C318C3      ; Loop if not
         RTS

; Set to condense BG3 text (save file confirmation, Colosseum matchup)
C318D1:  LDA #$02        ; 1Rx2B to PPU
         STA $4350       ; Set DMA mode
         LDA #$12        ; $2112
         STA $4351       ; To BG3 V-Scroll
         LDY #C318F0     ; C3/18F0
         STY $4352       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4354       ; Set src HB
         LDA #$C3        ; ...
         STA $4357       ; Set indir HB
         LDA #$20        ; Channel: 5
         TSB $43         ; Queue HDMA-5
         RTS

; Text shifting table for the above
C318F0:  db $20,$00,$00  ; 32 lines, shift by 0 px
         db $0C,$04,$00  ; 12 lines, shift by 4 px
         db $0C,$08,$00  ; 12 lines, shift by 8 px
         db $08,$C8,$FF  ; 8 lines, shift by -38 px
         db $50,$00,$00  ; 80 lines, shift by 0 px
         db $58,$00,$00  ; 88 lines, shift by 0 px
         db $00          ; End

; Create actor sprites for Save or Load menu
C31903:  LDX $00         ; Actor slot: 1
C31905:  LDA $7EAA71,X   ; Empty slot?
         BMI C31977      ; Skip if so
         PHX             ; Save slot
         PHX             ; Save slot
         LDA #$03        ; Min slot: 24
         LDY #C319C7     ; C3/19C7
         JSR C31173      ; Queue OAM fn
         TXY             ; Queue index
         PLX             ; Actor slot
         PHB             ; Save DB
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         LDA $66         ; On "New Game"?
         BEQ C31931      ; Branch if so
         CMP #$01        ; On file 1?
         BEQ C31943      ; Branch if so
         CMP #$02        ; On file 2?
         BEQ C3193A      ; Branch if so
         LDA.L C319BB,X  ; OAM complements
         STA $3749,Y     ; Set sprite's
         BRA C3194A      ; Set coords/ptr

; Fork: New Game
C31931:  LDA.L C31997,X  ; OAM complements
         STA $3749,Y     ; Set sprite's
         BRA C3194A      ; Set coords/ptr

; Fork: Save file 2
C3193A:  LDA.L C319AF,X  ; OAM complements
         STA $3749,Y     ; Set sprite's
         BRA C3194A      ; Set coords/ptr

; Fork: Save file 1
C31943:  LDA.L C319A3,X  ; OAM complements
         STA $3749,Y     ; Set sprite's
C3194A:  LDA #$D8        ; Bank: D8
         STA $35CA,Y     ; Set anim ptr HB
         TDC             ; Clear A
         STA $33CB,Y     ; No use...
         STA $344B,Y     ; No use...
         LDA.L C3197F,X  ; X position
         STA $33CA,Y     ; Set sprite's
         LDA.L C3198B,X  ; Y position
         STA $344A,Y     ; Set sprite's
         LDA $7EAA71,X   ; Graphics set
         REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAX             ; Index it
         LDA $D8E917,X   ; Anim table ptr
         STA $32C9,Y     ; Set sprite's
         SEP #$20        ; 8-bit A
         PLB             ; Restore DB
         PLX             ; Actor slot
C31977:  INX             ; Point to next
         CPX #$000C      ; Done all 12?
         BNE C31905      ; Loop if not
         SEC             ; ...
         RTS

; X positions for actors on save files
C3197F:  dw $6850,$9880  ; File 1
         dw $6850,$9880  ; File 2
         dw $6850,$9880  ; File 3

; Y positions for actors on save files
C3198B:  dw $4040,$4040  ; File 1
         dw $7878,$7878  ; File 2
         dw $B0B0,$B0B0  ; File 3

; Actors' OAM complements when on "New Game"
C31997:  dw $0202,$0202  ; File 1: Grayscale
         dw $0202,$0202  ; File 2: Grayscale
         dw $0202,$0202  ; File 3: Grayscale

; Actors' OAM complements when on save file 1
C319A3:  dw $0000,$0000  ; File 1: None
         dw $0202,$0202  ; File 2: Grayscale
         dw $0202,$0202  ; File 3: Grayscale

; Actors' OAM complements when on save file 2
C319AF:  dw $0202,$0202  ; File 1: Grayscale
         dw $0000,$0000  ; File 2: None
         dw $0202,$0202  ; File 3: Grayscale

; Actors' OAM complements when on save file 3
C319BB:  dw $0202,$0202  ; File 1: Grayscale
         dw $0202,$0202  ; File 2: Grayscale
         dw $0000,$0000  ; File 3: None

; Display actor's sprite on save file
C319C7:  LDX $2D         ; Queue index
         JSR C31206      ; Set pose timer
         JSR C31221      ; Define OAM
         CLC             ; Set to dequeue
         RTS

; Compute SRAM checksum
C319D1:  STZ $E7         ; Sum LB: 0
         STZ $E8         ; Sum HB: 0
         LDX $00         ; Index: 0
         CLC             ; Prepare ADC
C319D8:  LDA $1600,X     ; SRAM data
         ADC $E7         ; Add sum LB
         STA $E7         ; Set sum LB
         TDC             ; Clear A
         ADC $E8         ; Add HB + C
         STA $E8         ; Set sum HB
         INX             ; Index +1
         CPX #$09FE      ; At checksum?
         BNE C319D8      ; Loop if not
         RTS

; Load and validate SRAM checksum (buggy if zero)
C319EB:  REP #$20        ; 16-bit A
         LDA $E7         ; Actual checksum
         CMP $1FFE       ; Sum in save file
         BNE C319F6      ; Use 0 if unalike
         BRA C319F7      ; Skip a line
C319F6:  TDC             ; Clear checksum
C319F7:  TAY             ; Put sum in Y
         SEP #$20        ; 8-bit A
         RTS

; 53: Queue fade-out for save menu
C319FB:  JSR C3304F      ; Queue fade-out
         LDY #$0008      ; Frames: 8
         STY $20         ; Set fade timer
         LDA #$54        ; C3/1A19
         STA $26         ; Next: Wait
         JMP C31903      ; Refresh actors

; 52: Queue fade-in for save menu
C31A0A:  JSR C33056      ; Queue fade-in
         LDY #$0008      ; Frames: 8
         STY $20         ; Set fade timer
         LDA #$54        ; C3/1A19
         STA $26         ; Next: Wait
         JMP C31903      ; Create actors

; 54: Wait while save menu fades in or out
C31A19:  LDY $20         ; Timer expired?
         BNE C31A21      ; Branch if not
         LDA $27         ; Queued command
         STA $26         ; Execute it next
C31A21:  JMP C31903      ; Refresh actors

; Positioned text for save menus
C31A24:  dw $7A4F : db "Empty",$00
C31A2C:  dw $7C0F : db "Empty",$00
C31A34:  dw $7DCF : db "Empty",$00
C31A3C:  dw $7ACF : db "Time",$00
C31A43:  dw $7C8F : db "Time",$00
C31A4A:  dw $7E4F : db "Time",$00
C31A51:  dw $7B11 : db ":",$00
C31A55:  dw $7CD1 : db ":",$00
C31A59:  dw $7E91 : db ":",$00
C31A5D:  dw $7A7B : db "LV",$00
C31A62:  dw $7C3B : db "LV",$00
C31A67:  dw $7DFB : db "LV",$00
C31A6C:  dw $7AFB : db "/",$00
C31A70:  dw $7CBB : db "/",$00
C31A74:  dw $7E7B : db "/",$00
C31A78:  dw $7967 : db "Save",$00
C31A7F:  dw $7963 : db "New Game",$00

; 04: Initialize main menu
C31A8A:  JSR C3352F      ; Reset/Stop stuff
         JSR C31BA8      ; Load portraits
         JSR C30F89      ; Stop VRAM DMA B
         JSR C33A6B      ; Set Win2 bounds
         LDA #$04        ; Channel: 2
         TSB $43         ; Queue Win1 HDMA
         JSR C30F89      ; Again...
         JSR C36904      ; Reset BGs' X/Y
         LDA #$03        ; 64x64 at $0000
         STA $2107       ; Set BG1 map loc
         LDA #$43        ; 64x64 at $4000
         STA $2109       ; Set BG3 map loc
         LDA #$C0        ; Channels: 6, 7
         TRB $43         ; Halt HDMA 6+7
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         JSR C330F5      ; Draw menu
         LDA #$00        ; Min slot: 0
         LDY #C32F42     ; C3/2F42
         JSR C31173      ; Queue D-Pad fn
         JSR C307B0      ; Queue cursor OAM
         JSR C3354E      ; HDMA: MS desig.
         LDY #$0002      ; Y: 2
         STY $37         ; Set BG1 Y-Pos
         JSR C336A3      ; Set to shift BG3
         LDA #$05        ; C3/1DA4
         STA $27         ; Queue: Sustain menu
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         JMP C33541      ; BRT:1 + NMI

; 07: Initialize Item menu
C31AD6:  JSR C31AE2      ; Init list vars
         JSR C31AFE      ; Draw menu; cursor
         JSR C31B0E      ; Shift & OBJ & Fade
         JMP C31B2E      ; Queue: Choice 1

; Initialize item list variables (Item, Colosseum)
C31AE2:  JSR C3352F      ; Reset/Stop stuff
         JSR C31B99      ; Queue desc anim
         JSR C36904      ; Reset BGs' X/Y
         STZ $4A         ; List scroll: 0
         STZ $49         ; Top BG1 WR row: 1
         LDA #$F5        ; Top row: Slot 246
         STA $5C         ; Set scroll limit
         LDA #$0A        ; Onscreen rows: 10
         STA $5A         ; Set rows per page
         LDA #$01        ; Onscreen cols: 1
         STA $5B         ; Set cols per page
         JMP C37D1C      ; Load navig data

; Draw Item menu, position cursor in inventory
C31AFE:  LDA $1D4E       ; Game options
         AND #$40        ; Cursor memory?
         BEQ C31B08      ; Branch if not
         JSR C30DAC      ; Restore cursor
C31B08:  JSR C37D25      ; Relocate cursor
         JMP C37DA3      ; Draw menu; elems

; Initiate text shifting, sprites, fade-in (Item, Colosseum)
C31B0E:  JSR C37E2B      ; Set to shift text
         JSR C307B0      ; Queue cursor OAM
         JSR C3091F      ; Create scrollbar
         REP #$20        ; 16-bit A
         LDA #$0070      ; V-Speed: 0.44 px
         STA $7E354A,X   ; Set scrollbar's
         LDA #$0058      ; Y: 88
         STA $7E34CA,X   ; Set scrollbar's
         SEP #$20        ; 8-bit A
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         RTS

; Queue Item menu choice 1, prepare fade-in
C31B2E:  LDA #$08        ; C3/1EF7
         STA $27         ; Queue: Choice 1
         JMP C33541      ; BRT:1 + NMI

; 77: Return from item usage menu
C31B35:  JSR C31AE2      ; Init list vars
         LDA $8E         ; Old cursor column
         STA $4D         ; Set onscreen col
         LDY $8E         ; Old cursor loc
         STY $4F         ; Set as current
         LDA $90         ; Old scroll pos
         STA $4A         ; Set as current
         LDA $4A         ; ...
         STA $E0         ; Memorize it...
         LDA $50         ; List row
         SEC             ; Prepare SBC
         SBC $E0         ; Sub scroll pos
         STA $4E         ; Set cursor row
         JSR C37D25      ; Relocate cursor
         JSR C37DA3      ; Draw menu; elems
         JSR C31B0E      ; Shift & OBJ & Fade
         JMP C31B2E      ; Queue: Choice 1

; 09: Initialize Skills menu
C31B5B:  JSR C3352F      ; Reset/Stop stuff
         TDC             ; Clear A
         LDA $28         ; Member slot
         TAX             ; Index it
         LDA $69,X       ; Actor in slot
         JSL $C20006     ; Get actor stats
         JSR C31BA8      ; Load portraits
         JSR C36A08      ; Set Win1 bounds
         STZ $4A         ; List scroll: 0
         STZ $49         ; Top BG1 WR row: 1
         JSR C34DBC      ; Set to shift text
         JSR C34C80      ; Draw menu, etc.
         JSR C34B50      ; Load navig data
         LDA $1D4E       ; Game options
         AND #$40        ; Cursor memory?
         BEQ C31B85      ; Branch if not
         JSR C30DFF      ; Restore cursor
C31B85:  JSR C34B59      ; Relocate cursor
         JSR C307B0      ; Queue cursor OAM
         JSR C31B99      ; Queue desc anim
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         LDA #$0A        ; C3/1FF4
         STA $27         ; Queue: Sustain menu
         JMP C33541      ; BRT:1 + NMI

; Set to update and upload description
C31B99:  JSR C3A796      ; Clear desc GFX
         JSR C3A991      ; Queue desc upload
         LDA #$00        ; Min slot: 0
         LDY #C3A80E     ; C3/A80E
         JSR C31173      ; Queue desc update
         RTS

; Load portrait graphics and colors for party
C31BA8:  JSR C36915      ; Get party info
         JSR C36E82      ; Load graphics
         JSR C36C09      ; Load colors
         LDA #$05        ; Show cursor: Y
         TSB $45         ; Unfreeze CGRAM
         JMP C314D2      ; Refresh CGRAM

; 35: Initialize Equip menu
C31BB8:  JSR C31BBD      ; Init variables
         BRA C31BD7      ; Draw menu, etc.

; Initialize variables for Equip menu
C31BBD:  JSR C3352F      ; Reset/Stop stuff
         JSR C36A08      ; Set Win1 bounds
         LDA #$06        ; Main cursor: On
         TSB $46         ; Set menu flag
         STZ $4A         ; List scroll: 0
         STZ $49         ; Top BG1 WR row: 1
         JSR C394B6      ; Set to shift text
         JSR C38E50      ; Load navig data
         JSR C38E59      ; Relocate cursor
         JMP C307B0      ; Queue cursor OAM

; Draw Equip menu, update status based on gear, trigger fade-in
C31BD7:  JSR C39032      ; Draw menu; status
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         LDA #$36        ; C3/9621
         STA $27         ; Queue: Option list
         JMP C33541      ; BRT:1 + NMI

; 7E: Swap actor in Equip menu, retain Equip mode
C31BE5:  JSR C31C01      ; Draw menu, etc.
         JSR C3964F      ; Draw blue "EQUIP"
         JSR C31C0A      ; Cursor & Fade-in
         LDA #$55        ; C3/9884
         JMP C31C15      ; Queue slot choice

; 7F: Swap actor in Equip menu, retain Remove mode
C31BF3:  JSR C31C01      ; Draw menu, etc.
         JSR C39656      ; Draw blue "REMOVE"
         JSR C31C0A      ; Cursor & Fade-in
         LDA #$56        ; C3/98CF
         JMP C31C15      ; Queue slot choice

; Redraw Equip menu after actor swap
C31C01:  JSR C31BBD      ; Reset variables
         JSR C39032      ; Draw menu; status
         JMP C39614      ; Switch windows

; Put cursor on first gear slot, trigger fade-in
C31C0A:  JSR C38E6C      ; Load navig data
         JSR C38E75      ; Relocate cursor
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         RTS

; Set queued menu command, prepare fade-in
C31C15:  STA $27         ; Set queued cmd
         JMP C33541      ; BRT:1 + NMI

; 6D: Open Equip menu after optimizing gear
C31C1A:  JSR C31BBD      ; Init variables
         JSR C396F0      ; Optimize gear
         LDA #$02        ; Menu: Equip
         STA $25         ; Set submenu
         BRA C31BD7      ; Draw menu, etc.

; 6E: Open Equip menu after removing all gear
C31C26:  JSR C31BBD      ; Init variables
         JSR C396A8      ; Remove gear
         LDA #$02        ; Menu: Equip
         STA $25         ; Set submenu
         BRA C31BD7      ; Draw menu, etc.

; 38: Initialize party gear overview
C31C32:  JSR C3352F      ; Reset/Stop stuff
         JSR C39497      ; Set to shift text
         JSR C38EED      ; Draw menu
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         LDA #$39        ; C3/2966
         STA $27         ; Queue: Sustain menu
         JMP C33541      ; BRT:1 + NMI

; 0B: Initialize Status menu
C31C46:  JSR C3352F      ; Reset/Stop stuff
         JSR C3620B      ; Set to shift text
         JSR C35D05      ; Draw menu; portrait
         JSR C31C5D      ; Init cursor data
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         LDA #$0C        ; C3/21F5
         STA $27         ; Queue: Sustain menu
         JMP C33541      ; BRT:1 + NMI

; Initialize cursor data for Status menu
C31C5D:  TDC             ; Clear A
         LDA $28         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         LDY $6D,X       ; Actor's address
         LDA $0000,Y     ; Actor
         CMP #$0C        ; Gogo?
         BNE C31C78      ; Abort if not
         JSR C336FF      ; Load navig data
         JSR C33708      ; Relocate cursor
         LDA #$06        ; Main cursor: On
         TSB $46         ; Set menu flag
         JMP C307B0      ; Queue cursor OAM
C31C78:  LDA #$06        ; Main cursor: Off
         TRB $46         ; Set menu flag
         RTS

; 0D: Initialize Config menu
C31C7D:  JSR C3352F      ; Reset/Stop stuff
         STZ $4A         ; Screen: 1st
         JSR C33A4C      ; Set Win2 bounds
         JSR C3389E      ; Draw menu, etc.
         JSR C33858      ; Load navig data
         LDA $5F         ; Return position
         STA $4E         ; Set cursor row
         JSR C33861      ; Relocate cursor
         JSR C307B0      ; Queue cursor OAM
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         LDA #$0E        ; C3/22C5
         STA $27         ; Queue: Sustain menu
         JMP C33541      ; BRT:1 + NMI

; 13: Initialize Save menu
C31CA0:  JSR C3352F      ; Reset/Stop stuff
         LDY #$0002      ; Y: 2
         STY $37         ; Set BG1 Y-Pos
         JSR C336A3      ; Set to shift BG3...
         LDA #$E3        ; CH: 0-1, 5-7
         TRB $43         ; Halt HDMA channels
         JSR C315EC      ; Draw menu, get chars
         JSR C36CC7      ; Load actor colors
         JSR C36C84      ; Load cursor colors
         JSR C315A4      ; Load navig data
         LDY $91         ; File 1 checksum
         BNE C31CC7      ; Branch if not 0
         LDY $93         ; File 2 checksum
         BNE C31CC7      ; Branch if not 0
         LDY $95         ; File 3 checksum
         BEQ C31CCD      ; Branch if 0
C31CC7:  LDA $0224       ; Last viewed file
         DEC A           ; Now 0-2
         STA $4E         ; Set cursor row
C31CCD:  JSR C315AD      ; Relocate cursor
         JSR C307B0      ; Queue cursor OAM
         LDA $4B         ; Cursor slot
         INC A           ; Now 1-3
         STA $66         ; Set active file
         LDA #$52        ; C3/1A0A
         STA $26         ; Next: Fade-in
         LDA #$14        ; C3/2540
         STA $27         ; Queue: Sustain menu
         JMP C33541      ; BRT:1 + NMI

; 15: Initialize save confirmation
C31CE3:  JSR C3352F      ; Reset/Stop stuff
         JSR C36915      ; Get party info
         JSR C33128      ; Draw menu
         JSR C315D4      ; Load navig data
         JSR C315DD      ; Relocate cursor
         JSR C307B0      ; Queue cursor OAM
         JSR C318D1      ; Set to shift text
         LDA #$16        ; C3/259D
         STA $27         ; Queue: Sustain menu
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         JMP C33541      ; BRT:1 + NMI

; 20: Initialize Load menu
C31D03:  JSR C3352F      ; Reset/Stop stuff
         LDY #$0002      ; Y: 2
         STY $37         ; Set BG1 Y-Pos
         JSR C336A3      ; Set to shift BG3...
         LDA #$E3        ; CH: 0-1, 5-7
         TRB $43         ; Halt HDMA channels
         LDY $00         ; X: 0
         STY $35         ; Set BG1 X-Pos
         STY $39         ; Set BG2 X-Pos
         STY $3D         ; Set BG3 X-Pos
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         JSR C31608      ; Draw menu, get chars
         JSR C36CC7      ; Load actor colors
         JSR C36C84      ; Load cursor colors
         JSR C315B8      ; Load navig data
         LDY $91         ; File 1 checksum
         BNE C31D36      ; Branch if not 0
         LDY $93         ; File 2 checksum
         BNE C31D36      ; Branch if not 0
         LDY $95         ; File 3 checksum
         BEQ C31D3C      ; Branch if 0
C31D36:  LDA $307FF0     ; Last altered file
         STA $4E         ; Set cursor row
C31D3C:  JSR C315C1      ; Relocate cursor
         JSR C307B0      ; Queue cursor OAM
         LDA $4B         ; Cursor slot
         STA $66         ; Set active file
         LDA #$21        ; C3/29C2
         STA $27         ; Queue: Sustain menu
         LDA #$52        ; C3/1A0A
         STA $26         ; Next: Fade-in
         JMP C33541      ; BRT:1 + NMI

; 22: Initialize load confirmation
C31D51:  JSR C3352F      ; Reset/Stop stuff
         JSR C36915      ; Get party info
         JSR C3314C      ; Draw menu
         JSR C315D4      ; Load navig data
         JSR C315DD      ; Relocate cursor
         JSR C307B0      ; Queue cursor OAM
         JSR C318D1      ; Set to shift text
         LDA #$23        ; C3/B466
         STA $27         ; Queue: Sustain menu
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         JMP C33541      ; BRT:1 + NMI

; 00: Queue fade-out, prepare transition
C31D71:  JSR C3304F      ; Queue fade-out
         LDY #$0008      ; Frames: 8
         STY $20         ; Set fade timer
         LDA #$02        ; C3/1D8B
         STA $26         ; Next: Wait
         RTS

; 01: Queue fade-in, prepare transition
C31D7E:  JSR C33056      ; Queue fade-in
         LDY #$0008      ; Frames: 8
         STY $20         ; Set fade timer
         LDA #$02        ; C3/1D8B
         STA $26         ; Next: Wait
         RTS

; 02: Wait while menu fades in or out
C31D8B:  LDY $20         ; Timer expired?
         BNE C31D93      ; Exit if not
         LDA $27         ; Queued command
         STA $26         ; Execute it next
C31D93:  RTS

; 03: Exit main menu's portrait area
C31D94:  LDA #$00        ; Min slot: 0
         LDY #C32F42     ; C3/2F42
         JSR C31173      ; Queue D-Pad fn
         JSR C307B0      ; Queue cursor OAM
         LDA #$05        ; C3/1DA4
         STA $26         ; Next: Main menu
         RTS

; 05: Sustain main menu
C31DA4:  JSR C33548      ; Redraw time
         LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C31DB0      ; Branch if not
         JMP C32E62      ; Handle selection

; Fork: Handle left
C31DB0:  LDA $09         ; No-autofire keys
         BIT #$02        ; Pushing left?
         BEQ C31DBC      ; Branch if not
         JSR C30EA3      ; Sound: Cursor
         JMP C32EC6      ; Init Order menu

; Fork: Handle B
C31DBC:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C31DD1      ; Exit if not
         STZ $0205       ; Clear field event
         JSR C30EA9      ; Sound: Cursor
         JSR C31DD2      ; Update field FX
         LDA #$FF        ; Null value
         STA $27         ; Queue menu exit
         STZ $26         ; Next: Fade-out
C31DD1:  RTS

; Update field effects from gear (Charms, Sprint Shoes)
C31DD2:  STZ $11DF       ; Clear effects
         LDX $00         ; Member slot: 1
C31DD7:  LDA $69,X       ; Actor in slot
         BMI C31DE1      ; Skip if none
         PHX             ; Save slot
         JSL $C20006     ; Load gear FX
         PLX             ; Member slot
C31DE1:  INX             ; Slot +1
         CPX #$0004      ; Done all 4?
         BNE C31DD7      ; Loop if not
         RTS

; 06: Handle single actor targeting in main menu
C31DE8:  JSR C33548      ; Redraw time
         LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C31DFD      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         LDA #$05        ; Blinker: Off
         TRB $46         ; Actor cursor: Off
         LDA #$03        ; C3/1D94
         STA $26         ; Next: Main menu
         RTS

; Fork: Handle MT mode switch
C31DFD:  LDA $09         ; No-autofire keys
         BIT #$02        ; Pushing left?
         BEQ C31E1F      ; Branch if not
         LDA $25         ; Selected menu
         CMP #$02        ; Equip?
         BEQ C31E0D      ; Branch if so
         CMP #$03        ; Relic?
         BNE C31E1F      ; Branch if not
C31E0D:  JSR C30EA3      ; Sound: Cursor
         LDA #$06        ; Main cursor: Off
         TRB $46         ; Set menu flag
         LDA #$37        ; C3/1EB5
         STA $26         ; Next: Target all
         LDA $4E         ; Cursor row
         STA $5E         ; Set return loc
         JMP C3089F      ; Create blinkers

; Fork: Handle A
C31E1F:  LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C31E2C      ; Exit if not
         LDA $4B         ; Cursor slot
         STA $28         ; Set member slot
         JMP C31E2D      ; Skip a line
C31E2C:  RTS             ; Exit
C31E2D:  JSR C31E4E      ; Can open menu?
         BCS C31E42      ; Fail if not
         TDC             ; Clear A
         LDA $25         ; Menu to open
         TAX             ; Index it
         LDA.L C31E49,X  ; Init command
         STA $27         ; Put in queue
         STZ $26         ; Next: Fade-out
         JSR C30EB2      ; Sound: Click
         RTS

; Fork: Inaccessible menu
C31E42:  JSR C30EC0      ; Play buzzer
         JSR C3305D      ; Pixelate screen
         RTS

; Initialization commands for actor menus
C31E49:  db $FF          ; Blank
         db $09          ; Skills
         db $35          ; Equip
         db $58          ; Relic
         db $0B          ; Status

; Determine if actor-related menu is accessible
C31E4E:  TDC             ; Clear A
         LDA $25         ; Menu to open
         CMP #$01        ; Skills?
         BEQ C31E89      ; Branch if so
         CMP #$02        ; Equip?
         BEQ C31E5F      ; Branch if so
         CMP #$03        ; Relic?
         BEQ C31E74      ; Branch if so
         BRA C31EB3      ; Allow access

; Fork: Equip
C31E5F:  TDC             ; ...
         LDA $28         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA $6D,X       ; Actor's address
         SEP #$20        ; 8-bit A
         TAX             ; Index it
         LDA $0000,X     ; Actor
         CMP #$0D        ; Umaro or guest?
         BCS C31EB1      ; Fail if so
         BRA C31E9C      ; Check if dead

; Fork: Relic
C31E74:  TDC             ; ...
         LDA $28         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA $6D,X       ; Actor's address
         SEP #$20        ; 8-bit A
         TAX             ; Index it
         LDA $0000,X     ; Actor
         CMP #$0E        ; Guest?
         BCS C31EB1      ; Fail if so
         BRA C31E9C      ; Check if dead

; Fork: Skills
C31E89:  JSR C34D3D      ; Set skill colors
         LDA #$24        ; Palette: Gray
         LDX $00         ; 1st: Espers
C31E90:  CMP $79,X       ; Grayed skill?
         BNE C31E9C      ; Branch if not
         INX             ; Skill slot +1
         CPX #$0007      ; Beyond Dance?
         BNE C31E90      ; Loop if not
         BRA C31EB1      ; Play buzzer

; Fork: Check if dead
C31E9C:  TDC             ; Clear A
         LDA $28         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA $6D,X       ; Actor address
         SEP #$20        ; 8-bit A
         TAX             ; Index it
         LDA $0014,X     ; Zombie? KO?
         AND #$C2        ; Or Petrify?
         BNE C31EB1      ; Fail if any
         BRA C31EB3      ; Allow access

; Fork: Set to play buzzer
C31EB1:  SEC             ; Mark failure
         RTS

; Fork: Set to open menu
C31EB3:  CLC             ; Mark success
         RTS

; 37: Handle multitargeting in main menu
C31EB5:  JSR C33548      ; Redraw time
         LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BNE C31EC4      ; Branch if so
         LDA $09         ; ...
         BIT #$01        ; Pushing right?
         BEQ C31EE5      ; Branch if not
C31EC4:  JSR C30EA9      ; Sound: Cursor
         JSR C32F98      ; Preload nav data
         JSR C307B0      ; Queue cursor OAM
         LDA #$00        ; Min slot: 0
         LDY #C32FC0     ; C3/2FC0
         JSR C31173      ; Queue D-Pad fn
         JSR C311B0      ; Run anim queue
         LDA $5E         ; Old cursor row
         STA $4E         ; Set as current
         LDA #$06        ; C3/1DE8
         STA $26         ; Next: ST actor
         LDA #$08        ; Blinkers: Off
         TRB $46         ; Set menu flag
         RTS

; Fork: Handle A
C31EE5:  LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C31EF5      ; Exit if not
         JSR C30EB2      ; Sound: Click
         STZ $26         ; Next: Fade-out
         LDA #$38        ; C3/1C32
         STA $27         ; Queue: Party gear
         RTS             ; ...
C31EF5:  RTS             ; ...
C31EF6:  RTS

; 08: Handle Item menu choice 1
C31EF7:  LDA #$10        ; Description: On
         TRB $45         ; Set menu flag
         TDC             ; Clear A
         STA $2A         ; List type: Stock
         JSR C30EFD      ; Queue list upload
         JSR C31F64      ; Handle L and R
         BCS C31EF6      ; Exit if pushed
         JSR C37D22      ; Handle D-Pad
         JSR C382F1      ; Load description

; Fork: Handle B
C31F0C:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C31F3B      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         LDY $4F         ; Cursor position
         STY $022F       ; To cursor memory
         LDA $4A         ; Scroll position
         STA $0231       ; To cursor memory
         JSR C37D80      ; Load navig data
         LDA $1D4E       ; Game options
         AND #$40        ; Cursor memory?
         BEQ C31F2E      ; Branch if not
         LDY $0234       ; Former position
         STY $4D         ; Set as current
C31F2E:  JSR C37D86      ; Relocate cursor
         LDA #$17        ; C3/25F4
         STA $26         ; Next: Option list
         JSR C38385      ; Blank item count
         JMP C30F39      ; Queue its upload

; Fork: Handle A
C31F3B:  LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C31F4F      ; Exit if not
         JSR C30EB2      ; Sound: Click
         LDA $4B         ; List slot
         STA $28         ; Set choice 1's
         LDA #$19        ; C3/2779
         STA $26         ; Next: Choice 2
         JMP C32F21      ; Create blinker
C31F4F:  RTS

; Hi-fork: Pressed L on first page
C31F50:  STZ $50         ; List row: 1
         STZ $4E         ; Cursor row: 1
         SEC             ; Mark L/R usage
         RTS

; Hi-fork: Pressed R on last page
C31F56:  LDA $54         ; Bottom menu row
         DEC A           ; Adjust value
         STA $4E         ; Set cursor row
         CLC             ; Prepare ADC
         ADC $4A         ; Add scroll pos
         STA $50         ; Set list row
         SEC             ; Mark L/R usage
         RTS

; Hi-fork: Do nothing
C31F62:  CLC             ; Mark no L/R use
         RTS

; Handle L and R for scrollable list
C31F64:  LDA $20         ; Scrolling now?
         BNE C31F62      ; Exit if so
         LDA $0A         ; Semi-auto keys
         BIT #$10        ; Pushing R?
         BEQ C31F93      ; Branch if not
         LDA $4A         ; Scroll position
         CMP $5C         ; At very bottom?
         BEQ C31F56      ; Branch if so
         LDA $5C         ; Scroll limit
         SEC             ; Prepare SBC
         SBC $4A         ; Get rows left
         CMP $5A         ; Full page below?
         BCS C31F7F      ; Branch if so
         BRA C31F81      ; Skip a line
C31F7F:  LDA $5A         ; Rows per page
C31F81:  STA $E0         ; Set shift qty
         LDA $4A         ; Scroll position
         CLC             ; Prepare ADC
         ADC $E0         ; Add shift qty
         STA $4A         ; Save changes
         LDA $50         ; List row
         CLC             ; Prepare ADC
         ADC $E0         ; Add shift qty
         STA $50         ; Save changes
         BRA C31FB7      ; Redraw & Sound

; Fork: Handle L
C31F93:  LDA $0A         ; Semi-auto keys
         BIT #$20        ; Pushing L?
         BEQ C31F62      ; Exit if not
         LDA $4A         ; On first page?
         BEQ C31F50      ; Branch if so
         CMP $5A         ; Full page above?
         BCS C31FA5      ; Branch if so
         LDA $4A         ; Scroll position
         BRA C31FA7      ; Skip a line
C31FA5:  LDA $5A         ; Rows per page
C31FA7:  STA $E0         ; Set shift qty
         LDA $4A         ; Scroll position
         SEC             ; Prepare SBC
         SBC $E0         ; Sub shift qty
         STA $4A         ; Save changes
         LDA $50         ; List row
         SEC             ; Prepare SBC
         SBC $E0         ; Sub shift qty
         STA $50         ; Save changes

; Fork: Redraw list, play sound effect
C31FB7:  JSR C30EA3      ; Sound: Cursor
         TDC             ; Clear A
         LDA $2A         ; List type
         ASL A           ; Double it
         TAX             ; Index it
         JSR (C31FC4,X)  ; Redraw list
         SEC             ; Mark L/R usage
         RTS

; Jump table for the above
C31FC4:  dw C31FD0       ; Inventory
         dw C31FD6       ; Magic
         dw C31FDC       ; Lore
         dw C31FE2       ; Rage
         dw C31FE8       ; Esper
         dw C31FEE       ; Gear

; Redraw inventory for page swap (Item, Colosseum, Sell)
C31FD0:  JSR C37E95      ; Load V-shift data
         JMP C37F88      ; Draw inventory

; Redraw Magic list for page swap
C31FD6:  JSR C34E2D      ; Load V-shift data
         JMP C34F87      ; Draw spell list

; Redraw Lore list for page swap
C31FDC:  JSR C34E2D      ; Load V-shift data
         JMP C3523C      ; Draw Lore list

; Redraw Rage list for page swap
C31FE2:  JSR C34E2D      ; Load V-shift data
         JMP C353A7      ; Draw Rage list

; Redraw Esper list for page swap
C31FE8:  JSR C34E2D      ; Load V-shift data
         JMP C3546C      ; Draw esper list

; Redraw gear list for page swap (Equip, Relic)
C31FEE:  JSR C39520      ; Load V-shift data
         JMP C39CAC      ; Draw item list

; 0A: Sustain Skills menu
C31FF4:  LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         LDA #$C0        ; Scrollbar: Off
         TRB $46         ; Set anim index
         JSR C34B56      ; Handle D-Pad
         LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C3200F      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         LDA #$04        ; C3/1A8A
         STA $27         ; Queue main menu
         STZ $26         ; Next: Fade-out
         RTS

; Fork: Handle A
C3200F:  LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C3201C      ; Branch if not
         LDA $4E         ; Cursor row
         STA $5E         ; Set return loc
         JMP C3208A      ; Invoke submenu

; Fork: Handle L and R, prepare for menu reset
C3201C:  LDA #$09        ; C3/1B5B
         STA $E0         ; Set init command
         BRA C32022      ; ...

; Handle member switching with L or R (excludes Status menu)
C32022:  LDA $B5         ; Mosaic settings
         AND #$F0        ; Mosaic enabled?
         BNE C32089      ; Exit if so
         LDA $08         ; No-autofire keys
         BIT #$10        ; Pushing R?
         BEQ C32059      ; Branch if not
         LDA $25         ; Submenu
         CMP #$03        ; Relic?
         BNE C3203F      ; Branch if not
         JSR C39EEB      ; Handle Reequip
         LDA $99         ; Triggered it?
         BEQ C3203F      ; Branch if not
         JSR C30EA3      ; Sound: Cursor
         RTS

; Fork: Switch to next member
C3203F:  TDC             ; Clear A
         LDA $28         ; Current member
         INC A           ; Point to next
         AND #$03        ; Wrap if last
         STA $28         ; Save changes
         TAX             ; Index it
         LDA $69,X       ; Nobody there?
         BMI C3203F      ; Skip if so
         JSR C31E4E      ; Can access menu?
         BCS C3203F      ; Skip if not
         LDA $E0         ; Init command
         STA $26         ; Set menu mode
         JSR C30EA3      ; Sound: Cursor
         RTS

; Fork: Handle L
C32059:  LDA $08         ; No-autofire keys
         BIT #$20        ; Pushing L?
         BEQ C32089      ; Exit if not
         LDA $25         ; Submenu
         CMP #$03        ; Relic?
         BNE C32070      ; Branch if not
         JSR C39EEB      ; Handle Reequip
         LDA $99         ; Triggered it?
         BEQ C32070      ; Branch if not
         JSR C30EA3      ; Sound: Cursor
         RTS

; Fork: Switch to preceding member
C32070:  TDC             ; Clear A
         LDA $28         ; Current member
         DEC A           ; Point to previous
         AND #$03        ; Wrap if was first
         STA $28         ; Save changes
         TAX             ; Index it
         LDA $69,X       ; Nobody there?
         BMI C32070      ; Skip if so
         JSR C31E4E      ; Can access menu?
         BCS C32070      ; Skip if not
         LDA $E0         ; Init command
         STA $26         ; Set menu mode
         JSR C30EA3      ; Sound: Cursor
C32089:  RTS

; Initialize selected Skills submenu if accessible
C3208A:  TDC             ; Clear A
         LDA $4B         ; Chosen menu
         TAX             ; Index it
         LDA $79,X       ; Name's color
         CMP #$20        ; User's color?
         BNE C3209E      ; Fail if not
         JSR C30EB2      ; Sound: Click
         LDA $4B         ; Chosen menu
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C320A5,X)  ; Invoke menu

; Fork: Play buzzer
C3209E:  JSR C30EC0      ; Play buzzer
         JSR C3305D      ; Pixelate screen
         RTS

; Jump table for the above
C320A5:  dw C320B3       ; Espers
         dw C3211C       ; Magic
         dw C320EE       ; SwdTech
         dw C32105       ; Blitz
         dw C3216E       ; Lore
         dw C321A6       ; Rage
         dw C321DE       ; Dance

; Initialize Espers menu
C320B3:  STZ $4A         ; List scroll: 0
         JSR C3091F      ; Create scrollbar
         REP #$20        ; 16-bit A
         LDA #$1000      ; V-Speed: 16 px
         STA $7E354A,X   ; Set scrollbar's
         LDA #$0068      ; Y: 104
         STA $7E34CA,X   ; Set scrollbar's
         SEP #$20        ; 8-bit A
         JSR C34C18      ; Load navig data
         JSR C34C21      ; Relocate cursor
         LDA #$06        ; Top row: Golem's
         STA $5C         ; Set scroll limit
         LDA #$08        ; Onscreen rows: 8
         STA $5A         ; Set rows per page
         LDA #$02        ; Onscreen cols: 2
         STA $5B         ; Set cols per page
         LDY #$0100      ; X: 256
         STY $39         ; Set BG2 X-Pos
         STY $3D         ; Set BG3 X-Pos
         JSR C35452      ; Draw espers, etc.
         LDA #$1E        ; C3/28D3
         STA $26         ; Next: Sustain menu
         JSR C32EEB      ; Create blinker
         RTS

; Initialize SwdTech menu
C320EE:  STZ $4A         ; List scroll: 0
         JSR C34BCE      ; Load navig data
         JSR C34BD7      ; Relocate cursor
         LDY #$0100      ; X: 256
         STY $39         ; Set BG2 X-Pos
         STY $3D         ; Set BG3 X-Pos
         JSR C352D7      ; Draw techs, etc.
         LDA #$3E        ; C3/298E
         STA $26         ; Next: Sustain menu
         RTS

; Initialize Blitz menu
C32105:  STZ $4A         ; List scroll: 0
         JSR C34BCE      ; Load navig data
         JSR C34BD7      ; Relocate cursor
         LDY #$0100      ; X: 256
         STY $39         ; Set BG2 X-Pos
         STY $3D         ; Set BG3 X-Pos
         JSR C355D4      ; Draw inputs, etc.
         LDA #$33        ; C3/2977
         STA $26         ; Next: Sustain menu
         RTS

; Initialize Magic menu
C3211C:  JSR C32130      ; Create scrollbar
         JSR C32148      ; Load nav data, etc.
         JSR C32158      ; Draw spells, etc.
         JSR C351C6      ; Draw MP cost
         JSR C30F4D      ; Queue BG3 upload
         LDA #$1A        ; C3/27E2
         STA $26         ; Next: Sustain menu
         RTS

; Create scrollbar for Magic menu
C32130:  STZ $4A         ; List scroll: 0
         JSR C3091F      ; Queue OAM fn
         REP #$20        ; 16-bit A
         LDA #$050D      ; V-Speed: 5.05 px
         STA $7E354A,X   ; Set sprite's
         LDA #$0068      ; Y: 104
         STA $7E34CA,X   ; Set sprite's
         SEP #$20        ; 8-bit A
         RTS

; Load navigation data for Magic menu; position cursor
C32148:  JSR C34B82      ; Load navig data
         LDA $1D4E       ; Game options
         AND #$40        ; Cursor memory?
         BEQ C32155      ; Branch if not
         JSR C30E0A      ; Restore cursor
C32155:  JMP C34B8B      ; Relocate cursor

; Switch to Magic menu, create portrait, draw spells and "MP…"
C32158:  LDA #$13        ; Top row: Sleep's
         STA $5C         ; Set scroll limit
         LDA #$08        ; Onscreen rows: 8
         STA $5A         ; Set rows per page
         LDA #$02        ; Onscreen cols: 2
         STA $5B         ; Set cols per page
         LDY #$0100      ; X: 256
         STY $39         ; Set BG2 X-Pos
         STY $3D         ; Set BG3 X-Pos
         JMP C34D7F      ; Draw spells, etc.

; Initialize Lore menu
C3216E:  STZ $4A         ; List scroll: 0
         JSR C3091F      ; Create scrollbar
         REP #$20        ; 16-bit A
         LDA #$0600      ; V-Speed: 6 px
         STA $7E354A,X   ; Set scrollbar's
         LDA #$0068      ; Y: 104
         STA $7E34CA,X   ; Set scrollbar's
         SEP #$20        ; 8-bit A
         JSR C34BF4      ; Load navig data
         JSR C34BFD      ; Relocate cursor
         LDA #$10        ; Top row: Dischord
         STA $5C         ; Set scroll limit
         LDA #$08        ; Onscreen rows: 8
         STA $5A         ; Set rows per page
         LDA #$01        ; Onscreen cols: 1
         STA $5B         ; Set cols per page
         LDY #$0100      ; X: 256
         STY $39         ; Set BG2 X-Pos
         STY $3D         ; Set BG3 X-Pos
         JSR C351F9      ; Draw lores, etc.
         LDA #$1B        ; C3/288A
         STA $26         ; Next: Sustain menu
         RTS

; Initialize Rage menu
C321A6:  STZ $4A         ; List scroll: 0
         JSR C3091F      ; Create scrollbar
         REP #$20        ; 16-bit A
         LDA #$00CC      ; V-Speed: 0.8 px
         STA $7E354A,X   ; Set scrollbar's
         LDA #$0068      ; Y: 104
         STA $7E34CA,X   ; Set scrollbar's
         SEP #$20        ; 8-bit A
         JSR C34C4C      ; Load navig data
         JSR C34C55      ; Relocate cursor
         LDA #$78        ; Top row: Tap Dancer
         STA $5C         ; Set scroll limit
         LDA #$08        ; Onscreen rows: 8
         STA $5A         ; Set rows per page
         LDA #$02        ; Onscreen cols: 2
         STA $5B         ; Set cols per page
         LDY #$0100      ; X: 256
         STY $39         ; Set BG2 X-Pos
         STY $3D         ; Set BG3 X-Pos
         JSR C35391      ; Draw rages, etc.
         LDA #$1D        ; C3/28BA
         STA $26         ; Next: Sustain menu
         RTS

; Initialize Dance menu
C321DE:  STZ $4A         ; List scroll: 0
         JSR C34BCE      ; Load navig data
         JSR C34BD7      ; Relocate cursor
         LDY #$0100      ; X: 256
         STY $39         ; Set BG2 X-Pos
         STY $3D         ; Set BG3 X-Pos
         JSR C35774      ; Draw dances, etc.
         LDA #$1C        ; C3/22AA
         STA $26         ; Next: Sustain menu
         RTS

; 0C: Sustain Status menu
C321F5:  JSR C30F39      ; Set to redraw cmds
         LDA $08         ; No-autofire keys
         BIT #$10        ; Pushing R?
         BEQ C3221E      ; Branch if not
         LDA $28         ; Member slot
         STA $79         ; Set former slot
C32202:  TDC             ; Clear A
         LDA $28         ; Member slot
         INC A           ; Point to next
         AND #$03        ; Wrap if was last
         STA $28         ; Save changes
         TAX             ; Index slot
         LDA $69,X       ; Nobody there?
         BMI C32202      ; Skip slot if so
         LDA $28         ; New member slot
         CMP $79         ; Matches former?
         BEQ C32218      ; Skip sound if so
         JSR C30EA3      ; Sound: Cursor
C32218:  JSR C31C5D      ; Init cursor data
         JMP C35D83      ; Swap actor info

; Fork: Handle L
C3221E:  LDA $08         ; No-autofire keys
         BIT #$20        ; Pushing L?
         BEQ C32244      ; Branch if not
         LDA $28         ; Member slot
         STA $79         ; Set former slot
C32228:  TDC             ; Clear A
         LDA $28         ; Member slot
         DEC A           ; Point to previous
         AND #$03        ; Wrap if was first
         STA $28         ; Save changes
         TAX             ; Index it
         LDA $69,X       ; Empty slot?
         BMI C32228      ; Loop if so
         LDA $28         ; New member slot
         CMP $79         ; Matches former?
         BEQ C3223E      ; Skip sound if so
         JSR C30EA3      ; Sound: Cursor
C3223E:  JSR C31C5D      ; Init cursor data
         JMP C35D83      ; Swap actor info

; Fork: Handle B
C32244:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C32254      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         LDA #$04        ; C3/1A8A
         STA $27         ; Queue main menu
         STZ $26         ; Next: Fade-out
         RTS

; Fork: Handle Gogo
C32254:  TDC             ; Clear A
         LDA $28         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         LDY $6D,X       ; Actor's address
         LDA $0000,Y     ; Actor
         CMP #$0C        ; Gogo?
         BNE C322B3      ; Exit if not
         JSR C33705      ; Handle D-Pad
         LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C322B3      ; Exit if not
         JSR C30EB2      ; Sound: Click
         LDA $4B         ; Cursor slot
         STA $E7         ; Memorize it
         STZ $E8         ; Clear HB
         TDC             ; Clear A
         LDA $28         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         LDY $6D,X       ; Actor's address
         REP #$20        ; 16-bit A
         TYA             ; Move it to A
         CLC             ; Prepare ADC
         ADC $E7         ; Add cursor slot
         TAY             ; Index sum
         SEP #$20        ; 8-bit A
         LDA $0016,Y     ; Chosen command
         CMP #$12        ; Mimic?
         BEQ C322B3      ; Exit if so
         JSR C32F06      ; Create blinker
         LDA $4E         ; Cursor row
         STA $5E         ; Set return loc
         LDA $4B         ; Cursor slot
         STA $64         ; Set altered slot
         LDA #$06        ; Frames: 6
         STA $20         ; Set scroll timer
         LDY #$000C      ; Speed: 12
         STY $9C         ; Set scroll speed
         LDA #$6A        ; C3/63A7
         STA $27         ; Queue: Shifted menu
         LDA #$65        ; C3/36E7
         STA $26         ; Next: Shift screen
         JSR C36403      ; Load navig data
         LDA $7E9D89     ; Command list size
         STA $54         ; Set number of rows
         JMP C3640C      ; Relocate cursor
C322B3:  RTS

; Menu command 6B (unused)
C322B4:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C322C4      ; Exit if not
         JSR C30EA9      ; Sound: Cursor
         LDA #$04        ; C3/1A8A
         STA $27         ; Queue main menu
         STZ $26         ; Next: Fade-out
         RTS             ; ...
C322C4:  RTS

; 0E: Sustain Config menu
C322C5:  JSR C30EE9      ; Queue list upload
         LDA $0B         ; Semi-auto keys
         BIT #$04        ; Pushing down?
         BEQ C322E0      ; Branch if not
         LDA $4E         ; Cursor row
         CMP #$08        ; On Controller?
         BNE C322E0      ; Branch if not
         LDA #$50        ; C3/3A00
         STA $26         ; Next: Scroll
         LDA #$11        ; Frames: 17
         STA $20         ; Set scroll timer
         JSR C30EA3      ; Sound: Cursor
         RTS

; Fork: Handle upward scrolling
C322E0:  LDA $0B         ; Semi-auto keys
         BIT #$08        ; Pushing up?
         BEQ C322FA      ; Branch if not
         LDA $4E         ; On top row?
         BNE C322FA      ; Branch if not
         LDA $4A         ; On first page?
         BEQ C322FA      ; Branch if so
         LDA #$51        ; C3/3A21
         STA $26         ; Next: Scroll
         LDA #$11        ; Frames: 17
         STA $20         ; Set scroll timer
         JSR C30EA3      ; Sound: Cursor
         RTS

; Fork: Handle B and D-Pad
C322FA:  LDA $4A         ; On first page?
         BEQ C32303      ; Branch if so
         JSR C33884      ; Handle P2 D-Pad
         BRA C32306      ; Skip a line
C32303:  JSR C3385E      ; Handle P1 D-Pad
C32306:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C32316      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         LDA #$04        ; C3/1A8A
         STA $27         ; Queue main menu
         STZ $26         ; Next: Fade-out
         RTS

; Fork: Handle left and right
C32316:  LDA $0B         ; Semi-auto keys
         BIT #$01        ; Pushing right?
         BNE C32322      ; Branch if so
         LDA $0B         ; ...
         BIT #$02        ; Pushing left?
         BEQ C32325      ; Branch if not
C32322:  JMP C33D2F      ; Change settings

; Fork: Handle A
C32325:  LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C3232E      ; Branch if not
         JMP C32331      ; Handle click

; Fork: Handle L and R
C3232E:  JMP C323EC      ; Handle L and R

; Fork: Handle clicked option
C32331:  LDA $4E         ; Cursor row
         STA $5F         ; Set return row
         LDA $4A         ; On first page?
         BNE C32342      ; Branch if not
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C3234A,X)  ; Handle option

; Waste of space...
C32341:  RTS

; Fork: Handle click on page 2
C32342:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C3235C,X)  ; Handle option

; Jump table for clicks in Config menu
C3234A:  dw C32341       ; Bat.Mode   (NOP)
         dw C32341       ; Bat.Speed  (NOP)
         dw C32341       ; Msg.Speed  (NOP)
         dw C32368       ; Cmd.Set
         dw C32341       ; Gauge      (NOP)
         dw C32341       ; Sound      (NOP)
         dw C32341       ; Cursor     (NOP)
         dw C32341       ; Reequip    (NOP)
         dw C32379       ; Controller
C3235C:  dw C32341       ; Mag.Order  (NOP)
         dw C32341       ; Window     (NOP)
         dw C32388       ; Color
         dw C32388       ; R
         dw C32388       ; G
         dw C32388       ; B

; Handle click on "Short" option
C32368:  LDA $1D4D       ; Game options
         BIT #$80        ; Short cmd set?
         BEQ C32341      ; Exit if not
         JSR C30EB2      ; Sound: Click
         LDA #$47        ; C3/42C2
         STA $27         ; Queue cmd menu
         STZ $26         ; Next: Fade-out
         RTS

; Handle click on "Multiple" option
C32379:  LDA $1D54       ; Multiplayer mode?
         BPL C32341      ; Exit if not
         JSR C30EB2      ; Sound: Click
         LDA #$4B        ; C3/46AD
         STA $27         ; Queue joypad menu
         STZ $26         ; Next: Fade-out
         RTS

; Handle color resetting in options
C32388:  JSR C30EB2      ; Sound: Click
         LDA $1D54       ; Game options
         AND #$38        ; Get viewed color
         BEQ C3239B      ; Branch if font
         JSR C323A7      ; Reset skin colors
         JSR C33A87      ; Refresh skin
         JMP C341C3      ; Redraw RGB info

; Fork: Reset font color
C3239B:  LDY #$7FFF      ; Color: White
         STY $1D55       ; Put in options
         JSR C33F99      ; Put in palettes
         JMP C341C3      ; Redraw RGB info

; Reset skin palette
C323A7:  TDC             ; Clear A
         LDA $1D4E       ; Game options
         AND #$0F        ; Get wallpaper
         REP #$20        ; 16-bit A
         TAY             ; Set loop counter
         STZ $EB         ; RAM index: 0
         STZ $ED         ; ROM index: 0
C323B4:  DEY             ; Counter -1
         BMI C323C9      ; Branch if < 0
         LDA #$000E      ; RAM struct size
         CLC             ; Prepare ADC
         ADC $EB         ; Add RAM index
         STA $EB         ; Set RAM index
         LDA #$0020      ; ROM struct size
         CLC             ; Prepare ADC
         ADC $ED         ; Add ROM index
         STA $ED         ; Set ROM index
         BRA C323B4      ; Loop

; Fork: Load skin palette
C323C9:  LDX #$312B      ; 7E/312B
         STX $2181       ; Set WRAM LBs
         LDA $EB         ; RAM index
         TAY             ; Index it
         LDA $ED         ; ROM index
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDA #$0E        ; Colors: 7
         STA $E9         ; Set counter
C323DB:  LDA $ED1C02,X   ; Color data
         STA $1D57,Y     ; Put in options
         STA $2180       ; Put in palette
         INX             ; ROM index +1
         INY             ; RAM index +1
         DEC $E9         ; One less byte
         BNE C323DB      ; Loop till last
         RTS

; Handle L and R in Config menu
C323EC:  LDA $08         ; No-autofire keys
         BIT #$10        ; Pushing R?
         BNE C323F6      ; Branch if so
         BIT #$20        ; Pushing L?
         BEQ C3240B      ; Exit if not
C323F6:  JSR C30EA3      ; Sound: Cursor
         STZ $5F         ; Return loc...
         LDA $4A         ; On first page?
         BNE C32406      ; Branch if not
         LDA #$01        ; Screen: 2nd
         STA $4A         ; Set active page
         JMP C339EA      ; Switch screens

; Fork: On page 2
C32406:  STZ $4A         ; Page: 1st
         JSR C339F5      ; Switch screens
C3240B:  RTS

; 0F: Handle Order menu choice 1
C3240C:  JSR C33548      ; Redraw time
         JSR C36989      ; Set SRAM party
         LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BNE C3241E      ; Branch if so
         LDA $09         ; ...
         BIT #$01        ; Pushing right?
         BEQ C32437      ; Branch if not
C3241E:  JSR C30EA9      ; Sound: Cursor
         LDA #$06        ; Frames: 6
         STA $20         ; Set scroll timer
         LDY #$000C      ; Speed: 12
         STY $9C         ; Set scroll speed
         LDA #$05        ; Blinker: Off
         TRB $46         ; Order cursor: Off
         LDA #$03        ; C3/1D94
         STA $27         ; Queue: Main menu
         LDA #$65        ; C3/36E7
         STA $26         ; Next: Pan screen
         RTS

; Fork: Handle A
C32437:  LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C32452      ; Exit if not
         JSR C30EB2      ; Sound: Click
         LDA $4B         ; Selected slot
         STA $28         ; Set choice 1
         LDA #$10        ; C3/2453
         STA $26         ; Next: Choice 2
         JSR C32F21      ; Create blinker
         JSR C32FB1      ; Unlock all slots
         LDA $4E         ; Cursor row
         STA $5E         ; Save for cancel
C32452:  RTS

; 10: Handle Order menu choice 2
C32453:  JSR C33548      ; Redraw time
         LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C3246F      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         LDA #$01        ; Blinker: Off
         TRB $46         ; Set menu flag
         LDA #$0F        ; C3/240C
         STA $26         ; Next: Choice 1
         JSR C32F98      ; Lock empty slots
         LDA $5E         ; Old cursor row
         STA $4E         ; Set as current
         RTS

; Fork: Change row
C3246F:  LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C324A8      ; Exit if not
         JSR C30EB2      ; Sound: Click
         LDA $28         ; First selection
         CMP $4B         ; Matches second?
         BNE C32491      ; Swap if not
         LDA #$01        ; Blinker: Off
         TRB $46         ; Set menu flag
         LDA #$12        ; C3/2537
         STA $26         ; Next: Wait
         JSR C32E10      ; Set row, scroll
         LDY #$000C      ; Frames: 12
         STY $20         ; Set wait timer
         JMP C32F98      ; Lock empty slots

; Fork: Switch members
C32491:  LDA #$10        ; Cursor: Freeze
         TRB $46         ; Set menu flag
         LDA #$0C        ; Cursor: Blank
         TRB $45         ; Unhide chars: N
         JSR C33582      ; Queue swap anim
         LDA #$18        ; Frames: 24
         STA $22         ; Set anim timer
         LDA #$01        ; Blinker: Off
         TRB $46         ; Set menu flag
         LDA #$11        ; C3/24A9
         STA $26         ; Next: Sustain swap
C324A8:  RTS

; 11: Switch members in Order menu
C324A9:  JSR C33548      ; Redraw time
         LDA $22         ; Timer expired?
         BEQ C324E0      ; Finalize if so
         CMP #$0C        ; Unhide point?
         BNE C324ED      ; Exit if not
         JSR C324F8      ; Swap battle pads
         JSR C32DD1      ; Swap actor info
         JSR C324EE      ; Clear icons/faces
         JSR C36A15      ; Erase party info
         JSR C332F1      ; Draw member 1 info
         JSR C3333D      ; Draw member 2 info
         JSR C33389      ; Draw member 3 info
         JSR C333D5      ; Draw member 4 info
         JSR C30DBA      ; Swap saved cursors
         JSR C30EFD      ; Queue stats upload
         JSR C32F98      ; Lock empty slots
         JSR C311B0      ; Run anim queue
         JSR C31368      ; Refresh screen
         LDA #$08        ; Unhide members: Y
         TSB $45         ; Set menu flag
         RTS

; Fork: Restore control
C324E0:  LDA #$0F        ; C3/240C
         STA $26         ; Next: Choice 1
         LDA #$10        ; Cursor: Unfreeze
         TSB $46         ; Set menu flag
         LDA #$04        ; Show cursor: Y
         TSB $45         ; Set menu flag
         RTS             ; ...
C324ED:  RTS

; Delete all portraits and status icons
C324EE:  JSR C32E3C      ; Portraits: Erase
         LDA #$01        ; Icons: Delete
         TRB $47         ; Set menu flag
         JMP C311B0      ; Run anim queue

; Swap assigned joypad for switched members
C324F8:  TDC             ; Clear A
         TAX             ; Member slot: 1
         STX $E0         ; Char 1+2: Pad 1
         STX $E2         ; Char 3+4: Pad 1
         LDA $1D4F       ; Game options
         CLC             ; Prepare ROR
C32502:  ROR A           ; Member's joypad
         BCC C32507      ; Skip if Pad 1
         INC $E0,X       ; Assign Pad 2
C32507:  INX             ; Member slot +1
         CPX #$0004      ; Done all 4?
         BNE C32502      ; Loop if not
         TDC             ; Clear A
         LDA $4B         ; Chosen slot B
         TAX             ; Index it
         LDA $E0,X       ; Member B's pad
         STA $E5         ; Memorize it
         LDA $28         ; Chosen slot A
         TAX             ; Index it
         LDA $E0,X       ; Member A's pad
         STA $E6         ; Memorize it
         LDA $E5         ; Member B's pad
         STA $E0,X       ; Set as A's
         LDA $4B         ; Chosen slot B
         TAX             ; Index it
         LDA $E6         ; Member A's pad
         STA $E0,X       ; Set as B's
         CLC             ; ...
         LDA $E3         ; Member 4's pad
         ASL A           ; Put in bit 1
         ADC $E2         ; Add member 3's
         ASL A           ; Put in bit 1-2
         ADC $E1         ; Add member 2's
         ASL A           ; Put in bit 1-3
         ADC $E0         ; Add member 1's
         STA $1D4F       ; Update options
         RTS

; 12: Wait while member changes row
C32537:  LDY $20         ; Timer expired?
         BNE C3253F      ; Exit if not
         LDA #$0F        ; C3/240C
         STA $26         ; Next: Choice 1
C3253F:  RTS

; 14: Sustain Save menu
C32540:  LDA $4B         ; Cursor slot
         INC A           ; Now 1-3
         STA $66         ; Set save slot
         JSR C31903      ; Refresh actors
         JSR C315AA      ; Handle D-Pad
         LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C3255D      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         LDA $9F         ; 04: C3/1A8A
         STA $27         ; Queue main menu
         LDA #$53        ; C3/19FB
         STA $26         ; Next: Fade-out
         RTS

; Fork: Handle A
C3255D:  LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C3259C      ; Exit if not
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         ASL A           ; Double it
         TAX             ; Index it
         LDY $91,X       ; Blank file?
         BNE C32580      ; Branch if not
         LDA $66         ; Save slot
         STA $021F       ; Link to game
         JSR C30EB9      ; Sound: Save
         JSR C325DF      ; Save game
         LDA $9E         ; Menu init cmd
         STA $27         ; Queue Save menu
         LDA #$53        ; C3/19FB
         STA $26         ; Next: Fade-out
         RTS

; Fork: Invoke confirmation menu
C32580:  JSR C30EB2      ; Sound: Click
         JSR C318AC      ; Back up SRAM data
         LDA $4B         ; Cursor slot
         INC A           ; Now 1-3
         STA $66         ; Set save slot
         JSR C31566      ; Load save file
         JSR C36915      ; Move party info
         JSR C36989      ; Set SRAM party
         LDA #$15        ; C3/1CE3
         STA $27         ; Queue submenu
         LDA #$53        ; C3/19FB
         STA $26         ; Next: Fade-out
C3259C:  RTS

; 16: Sustain save confirmation
C3259D:  JSR C315DA      ; Handle D-Pad
         LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BNE C325C2      ; Abort if so
         LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C325DE      ; Exit if not
         LDA $4B         ; Chose "No"?
         BNE C325C7      ; Abort if so
         LDA $66         ; Save slot
         STA $021F       ; Link to game
         JSR C30EB9      ; Sound: Save
         JSR C325DF      ; Save game
         LDA $9E         ; 13: C3/1CA0
         STA $27         ; Queue Save menu
         STZ $26         ; Next: Fade-out
         RTS

; Fork: Pushing B
C325C2:  JSR C30EA9      ; Sound: Cursor
         BRA C325CA      ; Skip a line

; Fork: Chose "No"
C325C7:  JSR C30EB2      ; Sound: Click
C325CA:  JSR C318C1      ; Restore SRAM
         JSR C36915      ; And party info
         JSR C36989      ; Set SRAM party
         LDA #$13        ; C3/1CA0
         STA $27         ; Queue Save menu
         STZ $26         ; Next: Fade-out
         LDA $66         ; File number
         STA $0224       ; Set last viewed
C325DE:  RTS

; Restore SRAM block and record game data
C325DF:  JSR C318C1      ; Restore SRAM
         JSR C36915      ; And party info
         JSR C36989      ; Set SRAM party
         REP #$20        ; 16-bit A
         INC $1DC7       ; Save count +1
         SEP #$20        ; 8-bit A
         LDA $66         ; File number
         JMP C3151D      ; Save game data

; 17: Handle Item menu options
C325F4:  LDA #$C0        ; Scrollbar: Off
         TRB $46         ; Set anim index
         LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         JSR C30EFD      ; Queue stock upload
         JSR C37D8C      ; Handle D-Pad
         LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C32611      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         LDA #$04        ; C3/1A8A
         STA $27         ; Queue main menu
         STZ $26         ; Next: Fade-out
C32611:  LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C3261D      ; Exit if not
         JSR C30EB2      ; Sound: Click
         JSR C3261E      ; Handle choice
C3261D:  RTS

; Handle selected Item menu option
C3261E:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C32626,X)  ; Handle option

; Jump table for the above
C32626:  dw C3262C       ; USE
         dw C3267C       ; ARRANGE
         dw C3268E       ; RARE

; Handle "USE" selection in Item menu
C3262C:  JSR C37D1C      ; Load navig data
         LDA $1D4E       ; Game options
         AND #$40        ; Cursor memory?
         BEQ C3263B      ; Branch if not
         JSR C30DAC      ; Restore cursor
         BRA C3264B      ; Skip cursor reset
C3263B:  LDA $0231       ; Old scroll pos
         STA $4A         ; Set as current
         LDY $4D         ; Cursor position
         STY $4F         ; Set as list loc
         LDA $4A         ; Scroll position
         CLC             ; Prepare ADC
         ADC $50         ; Add list V-Slot
         STA $50         ; Set list V-Slot
C3264B:  JSR C37D25      ; Relocate cursor
         JSR C37E0D      ; Draw inventory
         JSR C382F1      ; Desc; item count
         JSR C30F39      ; Queue BG3 upload
         JSR C31368      ; Refresh screen
         JSR C3091F      ; Create scrollbar
         REP #$20        ; 16-bit A
         LDA #$0070      ; V-Speed: 0.44 px
         STA $7E354A,X   ; Set scrollbar's
         LDA #$0058      ; Y: 88
         STA $7E34CA,X   ; Set scrollbar's
         SEP #$20        ; 8-bit A
         LDA #$08        ; C3/1EF7
         STA $26         ; Next: Choice 1
         LDA #$00        ; Min slot: 0
         LDY #C3A80E     ; C3/A80E
         JSR C31173      ; Queue desc update
         RTS

; Handle "ARRANGE" selection in Item menu
C3267C:  JSR C36A15      ; Hide inventory
         JSR C326B8      ; Move inventory
         JSR C326E0      ; Sort inventory
         JSR C37F88      ; Redraw inventory
         JSR C37D80      ; Load navig data
         JMP C31F2E      ; Move cursor, etc.

; Initialize rare item menu
C3268E:  JSR C37D44      ; Load navig data
         LDA $1D4E       ; Game options
         AND #$40        ; Cursor memory?
         BEQ C3269D      ; Branch if not
         LDY $0232       ; Former position
         STY $4D         ; Set as current
C3269D:  JSR C37D4D      ; Relocate cursor
         JSR C3838B      ; Draw item list
         JSR C31B99      ; Queue desc anim
         JSR C38339      ; Get desc/draw count
         JSR C30F39      ; Queue count upload
         JSR C31368      ; Refresh screen
         LDA #$C0        ; Scrollbar: Off
         TRB $46         ; Set anim index
         LDA #$18        ; C3/2741
         STA $26         ; Next: Sustain menu
         RTS

; Relocate inventory for sorting, delete original
C326B8:  TDC             ; ...
         TAX             ; Item slot: 1
C326BA:  LDA $1869,X     ; Item in slot
         STA $7EAA8D,X   ; Put in buffer
         LDA #$FF        ; Empty item
         STA $1869,X     ; Clear slot
         INX             ; Item slot +1
         CPX #$0100      ; Done all 256?
         BNE C326BA      ; Loop if not
         TDC             ; Clear A
         TAX             ; Item slot: 1
C326CE:  LDA $1969,X     ; Item quantity
         STA $7EAB8D,X   ; Put in buffer
         TDC             ; Quantity: 0
         STA $1969,X     ; Clear original
         INX             ; Item slot +1
         CPX #$0100      ; Done all 256?
         BNE C326CE      ; Loop if not
         RTS

; Sort inventory based on item icons
C326E0:  TDC             ; Clear A
         TAY             ; Item slot: 1
         TAX             ; Icon index: 0
C326E3:  LDA.L C326F5,X  ; Item icon
         PHX             ; Save index
         STA $E0         ; Set class
         JSR C32706      ; Get such items
         PLX             ; Icon index
         INX             ; Index +1
         CPX #$0011      ; Done 17 icons?
         BNE C326E3      ; Loop if not
         RTS

; Ordered list of item icons for Arrange command
C326F5:  db $FF          ; No icon
         db $D8          ; Dirk
         db $D9          ; Sword
         db $DA          ; Lance
         db $DB          ; Knife
         db $DC          ; Rod
         db $DD          ; Brush
         db $DE          ; Stars
         db $DF          ; Special
         db $E0          ; Gambler
         db $E1          ; Claw
         db $E2          ; Shield
         db $E3          ; Helmet
         db $E4          ; Armor
         db $E5          ; Tool
         db $E6          ; Skean
         db $E7          ; Relic

; Copy all items with given icon from buffer to inventory
C32706:  TDC             ; Clear A
         TAX             ; Buffer slot: 1
C32708:  PHX             ; Save buffer slot
         LDA $7EAA8D,X   ; Item in slot
         CMP #$FF        ; None?
         BEQ C32739      ; Skip if so
         STA $4202       ; Set multiplicand
         LDA #$0D        ; Name length
         STA $4203       ; Set multiplier
         NOP
         NOP
         NOP
         LDX $4216       ; Index product
         LDA $D2B300,X   ; Item icon
         CMP $E0         ; Sought type?
         BNE C32739      ; Skip if not
         PLX             ; Buffer slot
         LDA $7EAA8D,X   ; Item in slot
         STA $1869,Y     ; Put in stock
         LDA $7EAB8D,X   ; Item quantity
         STA $1969,Y     ; Put in stock
         INY             ; Stock slot +1
         BRA C3273A      ; Skip a line
C32739:  PLX             ; Buffer slot
C3273A:  INX             ; Buffer slot +1
         CPX #$0100      ; Done all 256?
         BNE C32708      ; Loop if not
         RTS

; 18: Sustain rare item menu
C32741:  LDA #$10        ; Description: On
         TRB $45         ; Set menu flag
         JSR C30EFD      ; Queue list upload
         JSR C37D4A      ; Handle D-Pad
         JSR C38339      ; Get desc/draw count
         LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C32778      ; Exit if not
         JSR C30EA9      ; Sound: Cursor
         LDA #$17        ; C3/25F4
         STA $26         ; Next: Option list
         LDY $4D         ; Cursor position
         STY $0232       ; To cursor memory
         JSR C37D80      ; Load navig data
         LDA $1D4E       ; Game options
         AND #$40        ; Cursor memory?
         BEQ C3276F      ; Branch if not
         LDY $0234       ; Former position
         STY $4D         ; Set as current
C3276F:  JSR C37D86      ; Relocate cursor
         JSR C38385      ; Blank item count
         JMP C30F39      ; Queue its upload
C32778:  RTS

; 19: Handle Item menu choice 2
C32779:  JSR C30EFD      ; Queue list upload
         JSR C37D22      ; Handle D-Pad
         JSR C382F1      ; Load description
         LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C32794      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         LDA #$01        ; Blinker: Off
         TRB $46         ; Set menu flag
         LDA #$08        ; C3/1EF7
         STA $26         ; Next: Choice 1
         RTS

; Fork: Handle A
C32794:  LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C327E1      ; Exit if not
         JSR C30EB2      ; Sound: Click
         LDA $28         ; First selection
         CMP $4B         ; Matches second?
         BNE C327AA      ; Swap them if not
         LDA #$01        ; Blinker: Off
         TRB $46         ; Set menu flag
         JMP C38497      ; Handle item

; Fork: Switch items
C327AA:  LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         LDA #$01        ; Blinker: Off
         TRB $46         ; Set menu flag
         LDA #$08        ; C3/1EF7
         STA $26         ; Next: Choice 1
         TDC             ; Clear A
         LDA $28         ; Slot A
         TAY             ; Index it
         LDA $1869,Y     ; Item A
         STA $E0         ; Save it
         LDA $1969,Y     ; Quantity A
         STA $E1         ; Save it
         TDC             ; ...
         LDA $4B         ; Slot B
         TAX             ; Index it
         LDA $1869,X     ; Item B
         STA $1869,Y     ; Replace A
         LDA $E0         ; Item A
         STA $1869,X     ; Replace B
         LDA $1969,X     ; Quantity B
         STA $1969,Y     ; Replace A
         LDA $E1         ; Quantity A
         STA $1969,X     ; Replace B
         JMP C37F88      ; Redraw list
C327E1:  RTS

; 1A: Sustain Magic menu
C327E2:  LDA #$10        ; Description: On
         TRB $45         ; Set menu flag
         LDA #$01        ; List type: Magic
         STA $2A         ; Set redraw mode
         JSR C30EFD      ; Queue list upload
         LDA $021E       ; Frame counter
         ROR A           ; Even value?
         BCC C327F8      ; Favor desc if so
         JSR C30F75      ; Queue cost upload
         BRA C327FB      ; Skip a line
C327F8:  JSR C3A991      ; Queue desc upload
C327FB:  JSR C31F64      ; Handle L and R
         BCS C32861      ; Exit if pushed
         JSR C34B88      ; Handle D-Pad
         JSR C356E5      ; Load description
         JSR C351C6      ; Draw MP cost

; Fork: Handle Y
C32809:  LDA $09         ; No-autofire keys
         BIT #$40        ; Pushing Y?
         BEQ C32822      ; Branch if not
         JSR C30EB2      ; Sound: Click
         LDA $9E         ; MP display switch
         EOR #$FF        ; Toggle it
         STA $9E         ; Save changes
         LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         JSR C34F1C      ; Build spell list
         JMP C34F87      ; Draw spell list

; Fork: Handle A
C32822:  LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C32855      ; Branch if not
         TDC             ; Clear A
         LDA $4B         ; Spell slot
         TAX             ; Index it
         LDA $7E9E09,X   ; Spell palette
         CMP #$20        ; User's color?
         BNE C32862      ; Fail if not
         JSR C30EB2      ; Sound: Click
         LDY $4F         ; Cursor position
         STY $8E         ; Set return loc
         LDA $4A         ; Scroll position
         STA $90         ; Set return loc
         LDA $4B         ; Cursor slot
         STA $99         ; Set spell slot
         JSR C32D13      ; Spell
         CMP #$12        ; X-Zone?
         BEQ C32869      ; Branch if so
         CMP #$2A        ; Warp?
         BEQ C32874      ; Branch if so
         LDA #$3A        ; C3/2A65
         STA $27         ; Queue usage menu
         STZ $26         ; Next: Fade-out
         RTS

; Fork: Handle B
C32855:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C32861      ; Exit if not
         JSR C30EFD      ; Queue BG1 upload
         JSR C329A5      ; Exit submenu
C32861:  RTS

; Fork: Unusable spell
C32862:  JSR C30EC0      ; Play buzzer
         JSR C3305D      ; Pixelate screen
         RTS

; Fork: X-Zone (unused)
C32869:  LDA $0201       ; Area permissions
         BIT #$01        ; Forbid X-Zone?
         BEQ C32862      ; Fail if so
         LDA #$04        ; Event: X-Zone
         BRA C3287D      ; Lower caster's MP

; Fork: Warp
C32874:  LDA $0201       ; Area permissions
         BIT #$02        ; Can warp here?
         BEQ C32862      ; Fail if not
         LDA #$03        ; Event: Warp
C3287D:  STA $0205       ; Set aftereffect
         JSR C32CEA      ; Lower caster's MP
         LDA #$FF        ; Null value
         STA $27         ; Queue menu exit
         STZ $26         ; Next: Fade-out
         RTS

; 1B: Sustain Lore menu
C3288A:  LDA #$10        ; Description: On
         TRB $45         ; Set menu flag
         LDA #$02        ; List type: Lores
         STA $2A         ; Set redraw mode
         JSR C30EFD      ; Queue list upload
         JSR C31F64      ; Handle L and R
         BCS C328A9      ; Exit if pushed
         JSR C34BFA      ; Handle D-Pad
         JSR C356EB      ; Load description
         LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C328A9      ; Exit if not
         JSR C329A5      ; Leave submenu
C328A9:  RTS

; 1C: Sustain Dance menu
C328AA:  JSR C30EFD      ; Queue list upload
         JSR C34BD4      ; Handle D-Pad
         LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C328B9      ; Exit if not
         JSR C329A5      ; Leave submenu
C328B9:  RTS

; 1D: Sustain Rage menu
C328BA:  LDA #$03        ; List type: Rages
         STA $2A         ; Set redraw mode
         JSR C30EFD      ; Queue list upload
         JSR C31F64      ; Handle L and R
         BCS C328D2      ; Exit if pushed
         JSR C34C52      ; Handle D-Pad
         LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C328D2      ; Exit if not
         JSR C329A5      ; Leave submenu
C328D2:  RTS

; 1E: Handle esper selection
C328D3:  LDA #$10        ; Description: On
         TRB $45         ; Set menu flag
         LDA #$04        ; List type: Espers
         STA $2A         ; Set redraw mode
         JSR C30EFD      ; Queue list upload
         JSR C31F64      ; Handle L and R
         BCS C32928      ; Exit if pushed
         JSR C34C1E      ; Handle D-Pad
         JSR C356DF      ; Load description
         LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C3291B      ; Branch if not
         JSR C30EB2      ; Sound: Click
         TDC             ; Clear A
         LDA $4B         ; Selected slot
         TAX             ; Index it
         LDA $7E9D89,X   ; Esper in slot
         CMP #$FF        ; None?
         BEQ C32908      ; Unequip if so
         STA $99         ; Memorize esper
         JSR C35897      ; Init submenu
         LDA #$4D        ; C3/58CE
         STA $26         ; Next: Data menu
         RTS

; Fork: Unequip esper
C32908:  LDA #$FF        ; Value for empty
         STA $E0         ; Set esper to equip
         JSR C32929      ; Clear esper held
         JSR C3546C      ; Redraw esper list
         JSR C30F11      ; Queue stats upload
         JSR C31368      ; Refresh held esper
         JMP C30EFD      ; Queue list upload

; Fork: Handle B
C3291B:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C32928      ; Exit if not
         LDA #$08        ; Blinker: Off
         TRB $46         ; Set menu flag
         JSR C329A5      ; Leave submenu
C32928:  RTS

; Equip and draw selected esper
C32929:  TDC             ; Clear A
         LDA $28         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         LDY $6D,X       ; Actor's address
         LDA $E0         ; Chosen esper
         STA $001E,Y     ; Assign to actor
         LDA $E0         ; ...
         JMP C34F08      ; Draw it by actor

; 34: Wait while showing who holds esper
C3293A:  LDY $20         ; Timer expired?
         BNE C32947      ; Exit if not
         LDY #C32948     ; Text pointer
         JSR C302F9      ; Blank message
         JMP C35913      ; Exit submenu
C32947:  RTS

; Positioned spaces for blanking "<actor> has it!"
C32948:  dw $40CD : db "                           ",$00

; 39: Sustain party gear overview
C32966:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C32976      ; Exit if not
         JSR C30EA9      ; Sound: Cursor
         LDA #$04        ; C3/1A8A
         STA $27         ; Queue main menu
         STZ $26         ; Next: Fade-out
         RTS             ; ...
C32976:  RTS

; 33: Sustain Blitz menu
C32977:  LDA #$10        ; Description: On
         TRB $45         ; Set menu flag
         JSR C30EFD      ; Queue list upload
         JSR C34BD4      ; Handle D-Pad
         JSR C35715      ; Load description
         LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C3298D      ; Exit if not
         JSR C329A5      ; Leave submenu
C3298D:  RTS

; 3E: Sustain SwdTech menu
C3298E:  LDA #$10        ; Description: On
         TRB $45         ; Set menu flag
         JSR C30EFD      ; Queue list upload
         JSR C34BD4      ; Handle D-Pad
         JSR C35700      ; Load description
         LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C329A4      ; Exit if not
         JSR C329A5      ; Leave submenu
C329A4:  RTS

; Return to Skills menu
C329A5:  JSR C30EA9      ; Sound: Cursor
         LDY $00         ; X: 0
         STY $39         ; Set BG2 X-Pos
         STY $3D         ; Set BG3 X-Pos
         LDA #$0A        ; C3/1FF4
         STA $26         ; Next: Skills menu
         JSR C34D27      ; Erase spell list
         JSR C34B50      ; Load navig data
         LDA $5E         ; Old cursor row
         STA $4E         ; Set as current
         JSR C34B59      ; Relocate cursor
         JMP C35807      ; Remove portrait

; 21: Sustain Load menu
C329C2:  LDA $4B         ; Cursor slot
         STA $66         ; Set save slot
         JSR C31903      ; Refresh actors
         JSR C315BE      ; Handle D-Pad
         LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C32A06      ; Exit if not
         TDC             ; Clear A
         LDA $4B         ; On new game?
         BEQ C32A07      ; Branch if so
         STA $66         ; Set save slot
         DEC A           ; Now 0-2
         ASL A           ; Double it
         TAX             ; Index it
         LDY $91,X       ; Blank file?
         BEQ C32A00      ; Fail if so
         JSR C318AC      ; Back up SRAM data
         JSR C30EB2      ; Sound: Click
         LDA $66         ; Chosen save file
         STA $0224       ; Set last viewed
         JSR C31566      ; Load save file
         JSR C36915      ; Move party info
         JSR C36989      ; Set SRAM party
         JSR C31595      ; Move timer data
         LDA #$22        ; C3/1D51
         STA $27         ; Queue confirm menu
         LDA #$53        ; C3/19FB
         STA $26         ; Next: Fade-out
         RTS

; Fork: Blank file
C32A00:  JSR C30EC0      ; Play buzzer
         JSR C3305D      ; Pixelate screen
C32A06:  RTS

; Fork: New game
C32A07:  JSR C30EB2      ; Sound: Click
         JSR C32A21      ; Reset play time
         LDA #$01        ; Save file: 1st
         STA $0224       ; Set last viewed
         STZ $021F       ; Game's file: None
         STZ $0205       ; Set new game mode
         LDA #$FF        ; Null value
         STA $27         ; Queue menu exit
         LDA #$53        ; C3/19FB
         STA $26         ; Next: Fade-out
         RTS

; Reset play time
C32A21:  TDC             ; Clear A
         TAY             ; Clear Y
         STY $021B       ; Zero hours, mins
         STY $021D       ; Zero secs, frames
         RTS

; 23: Sustain load confirmation
C32A2A:  JSR C315DA      ; Handle D-Pad
         LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BNE C32A58      ; Abort if so
         LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C32A64      ; Exit if not
         JSR C30EB2      ; Sound: Click
         LDA $4B         ; Chose "No"?
         BNE C32A5B      ; Abort if so
         LDY $1863       ; File's hrs, mins
         STY $021B       ; Set as current
         LDA $1865       ; File's seconds
         STA $021D       ; Set as current
         LDA $66         ; Loaded file
         STA $021F       ; Link to game
         LDA #$FF        ; Null value
         STA $27         ; Queue menu exit
         STZ $26         ; Next: Fade-out
         RTS

; Fork: Chose "No"
C32A58:  JSR C30EA9      ; Sound: Cursor
C32A5B:  JSR C318C1      ; Restore SRAM
         LDA #$20        ; C3/1D03
         STA $27         ; Queue Load menu
         STZ $26         ; Next: Fade-out
C32A64:  RTS

; 3A: Initialize spell usage menu
C32A65:  LDA #$40        ; No cursor memory
         TSB $45         ; Set menu flag
         JSR C32A76      ; Init variables
         JSR C35812      ; Draw menu
         JSR C307B0      ; Queue cursor OAM
         LDA #$3B        ; Queue: Sustain menu
         BRA C32AA5      ; Next: Fade-in

; Initialize variables for spell or item usage menu
C32A76:  JSR C3352F      ; Reset/Stop stuff
         LDA #$01        ; CGRAM: Refresh
         TSB $45         ; Set NMI flag
         LDA #$04        ; Channel: 2
         TSB $43         ; Queue Win1 HDMA
         STZ $1B         ; Null VRAM ptr LB
         STZ $1C         ; Null VRAM ptr HB
         JSR C36904      ; Reset BGs' X/Y
         JSR C31BA8      ; Load portraits
         LDA #$03        ; 64x64 at $0000
         STA $2107       ; Set BG1 map loc
         LDA #$C0        ; Channels: 6, 7
         TRB $43         ; Halt HDMA 6+7
         LDY #$0002      ; Y: 2
         STY $37         ; Set BG1 Y-Pos
         JSR C32F98      ; Preload nav data
         LDA #$00        ; Min slot: 0
         LDY #C32FC0     ; C3/2FC0
         JSR C31173      ; Queue D-Pad fn
         RTS

; Set queued menu command, trigger fade-in
C32AA5:  STA $27         ; Set queued cmd
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         JMP C33541      ; BRT:1 + NMI

; 3B: Handle single-target spell
C32AAE:  LDA $08         ; No-autofire keys
         BIT #$10        ; Pushing R?
         BNE C32AC6      ; Branch if so
         LDA $08         ; ...
         BIT #$20        ; Pushing L?
         BNE C32AC6      ; Branch if so
         LDA $09         ; No-autofire keys
         BIT #$01        ; Pushing right?
         BNE C32AC6      ; Branch if so
         LDA $09         ; ...
         BIT #$02        ; Pushing left?
         BEQ C32AF3      ; Branch if not
C32AC6:  JSR C30EA3      ; Sound: Cursor
         JSR C32D13      ; Spell
         JSR C350F5      ; Compute index
         REP #$21        ; 16-bit A; C-
         LDA $2134       ; Load index
         ADC #$0000      ; Add 0...
         TAX             ; Index it
         TDC             ; Clear A
         SEP #$20        ; 8-bit A
         LDA $C46AC0,X   ; Spell properties
         AND #$20        ; Can multi-target?
         BEQ C32AF3      ; Branch if not
         LDA $4E         ; Cursor row
         STA $5F         ; Save for revert
         LDA #$06        ; Main cursor: Off
         TRB $46         ; Set menu flag
         JSR C3089F      ; Create blinkers
         LDA #$3D        ; C3/2D78
         STA $26         ; Next: Target all
         RTS

; Fork: Handle A
C32AF3:  LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C32AFC      ; Branch if not
         JMP C32B0C      ; Handle spell

; Fork: Handle B
C32AFC:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C32B0B      ; Exit if not
         JSR C30EA9      ; Sound: Cursor
         LDA #$3C        ; C3/2D1C
         STA $27         ; Queue Magic menu
         STZ $26         ; Next: Fade-out
C32B0B:  RTS

; Handle spell usage on single target
C32B0C:  STZ $9C         ; Halve HP gain: N
         JSR C32CCC      ; Get LV, Mag.Pwr
         JSR C32D0B      ; Target's address
         JSR C32C14      ; Valid target?
         BCC C32B32      ; Fail if not
         JSR C32CEA      ; Lower caster's MP
         JSR C30EE5      ; Play heal sound
         JSR C32D0B      ; Target's address
         LDA $0014,Y     ; Status LB
         STA $F8         ; Set as target's
         LDA $0015,Y     ; Status HB
         STA $FB         ; Set as target's
         JSR C32B39      ; Adjust HP, status
         JMP C32BDE      ; Redo GFX, test MP

; Fork: Invalid target
C32B32:  JSR C30EC0      ; Play buzzer
         JSR C3305D      ; Pixelate screen
         RTS

; Adjust spell target's HP and status
C32B39:  LDA $000B,Y     ; Max HP LB
         STA $11B2       ; Set target's
         LDA $000C,Y     ; Max HP HB
         STA $11B3       ; Set target's
         PHY             ; Save index
         JSR C32D13      ; Spell number
         LDX $00         ; Mode: Magic
         JSL $C20009     ; Get gain/status
         PLY             ; Actor's address
         LDA $9C         ; One target?
         BEQ C32B5C      ; Branch if so
         REP #$21        ; 16-bit A; C-
         LDA $11B0       ; HP gain
         LSR A           ; Halve it
         BRA C32B61      ; Skip 2 lines
C32B5C:  REP #$21        ; 16-bit A; C-
         LDA $11B0       ; HP gain
C32B61:  ADC $0009,Y     ; Add actor HP
         STA $0009,Y     ; Set actor HP
         SEP #$20        ; 8-bit A
         JSR C32B9A      ; Enforce max
         LDA $FC         ; Status LB
         STA $0014,Y     ; Set actor's
         LDA $FF         ; Status HB
         STA $0015,Y     ; Set actor's
         LDA $9C         ; One target?
         BNE C32B99      ; Exit if not
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         TAX             ; Index it
         LDA $69,X       ; Actor's address
         JSL $C20006     ; Get gear data
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         ASL A           ; Double it
         TAX             ; Index it
         LDY $6D,X       ; Actor's address
         STY $67         ; Memorize it
         LDA $11D2       ; Immunities
         JSR C391EC      ; Deny ailments
         LDA $11D4       ; Auto status
         JMP C391FB      ; Handle Float
C32B99:  RTS

; Keep HP from exceeding max HP, clear Carry if lower
C32B9A:  LDA $000B,Y     ; Max HP LB
         STA $F3         ; Memorize it
         LDA $000C,Y     ; Max HP HB
         STA $F4         ; Memorize it
         JSR C30D65      ; Add gear bonus
         JSR C30D92      ; Cap at 9999
         REP #$20        ; 16-bit A
         LDA $0009,Y     ; Current HP
         CMP $F3         ; Under max?
         BCC C32BB9      ; Exit if so
         LDA $F3         ; Max HP
         STA $0009,Y     ; Set HP
         SEC             ; ...
C32BB9:  SEP #$20        ; 8-bit A
         RTS

; Keep MP from exceeding max MP, clear Carry if lower
C32BBC:  LDA $000F,Y     ; Max MP LB
         STA $F3         ; Memorize it
         LDA $0010,Y     ; Max MP HB
         STA $F4         ; Memorize it
         JSR C30D65      ; Add gear bonus
         JSR C30D9F      ; Cap at 999
         REP #$20        ; 16-bit A
         LDA $000D,Y     ; Current MP
         CMP $F3         ; Under max?
         BCC C32BDB      ; Exit if so
         LDA $F3         ; Max MP
         STA $000D,Y     ; Set MP
         SEC             ; ...
C32BDB:  SEP #$20        ; 8-bit A
         RTS

; Redraw party after spell usage, exit menu if short on MP
C32BDE:  JSR C32C01      ; Redraw party
         JSR C32CDF      ; Check caster gear
         JSR C32D03      ; Caster's address
         JSR C32D13      ; Spell used
         JSR C3510D      ; Define cost
         STX $E7         ; Memorize it
         LDX $000D,Y     ; Caster's MP
         CPX $E7         ; Can recast?
         BCS C32C00      ; Exit if so
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         LDA #$3C        ; C3/2D1C
         STA $27         ; Queue Magic menu
         STZ $26         ; Next: Fade-out
C32C00:  RTS

; Redraw party after spell or item usage
C32C01:  LDA $4B         ; Cursor slot, 0 if MT
         STA $9C         ; Set portrait slot
         JSR C324EE      ; Clear icons/portraits
         JSR C36A15      ; Clear names, stats
         JSR C33193      ; Redo stats/icons/faces
         JSR C36C09      ; Load portrait colors
         JMP C36EBF      ; Queue portrait upload

; Establish whether spell target is valid
C32C14:  LDA $0014,Y     ; Status
         AND #$80        ; Wound?
         BNE C32C40      ; Branch if so
         JSR C32D13      ; Spell
         CMP #$2D        ; Cure?
         BEQ C32C76      ; Branch if so
         CMP #$2E        ; Cure 2?
         BEQ C32C76      ; Branch if so
         CMP #$2F        ; Cure 3?
         BEQ C32C76      ; Branch if so
         CMP #$32        ; Antdot?
         BEQ C32C6D      ; Branch if so
         CMP #$33        ; Remedy?
         BEQ C32C64      ; Branch if so
         CMP #$22        ; Float?
         BEQ C32C4D      ; Branch if so
         CMP #$23        ; Imp?
         BEQ C32C84      ; Succeed if so
         CMP #$2C        ; Dispel?
         BEQ C32C56      ; Branch if so
         BRA C32C82      ; Make spell fail

; Fork: Wound
C32C40:  JSR C32D13      ; Spell
         CMP #$30        ; Life?
         BEQ C32C84      ; Succeed if so
         CMP #$31        ; Life 2?
         BEQ C32C84      ; Succeed if so
         BRA C32C82      ; Make spell fail

; Fork: Float
C32C4D:  LDA $0015,Y     ; Status
         AND #$80        ; Float?
         BNE C32C82      ; Fail if so
         BRA C32C84      ; Make spell work

; Fork: Dispel
C32C56:  LDA $0014,Y     ; Status LB
         AND #$7F        ; Ignore Wound...
         ORA $0015,Y     ; Add high byte
         AND #$90        ; Clear or Float?
         BEQ C32C82      ; Fail if neither
         BRA C32C84      ; Make spell work

; Fork: Remedy
C32C64:  LDA $0014,Y     ; Dark? Poison?
         AND #$45        ; Or Petrify?
         BEQ C32C82      ; Fail if none
         BRA C32C84      ; Make spell work

; Fork: Antdot
C32C6D:  LDA $0014,Y     ; Status
         AND #$04        ; Poison?
         BEQ C32C82      ; Fail if not
         BRA C32C84      ; Make spell work

; Fork: Cure spells
C32C76:  LDA $0014,Y     ; Zombie? KO?
         AND #$C2        ; Or Petrify?
         BNE C32C82      ; Fail if any
         JSR C32B9A      ; At full HP?
         BCC C32C84      ; Succeed if not
C32C82:  CLC             ; Make spell fail
         RTS             ; Exit
C32C84:  SEC             ; Make spell work
         RTS

; Handle spell usage on party
C32C86:  STZ $AF         ; Valid target: N
         LDA #$01        ; Half gain, etc.
         STA $9C         ; Set heal mode
         JSR C32CCC      ; Get LV, Mag.Pwr
         TDC             ; Member: 1st
C32C90:  PHA             ; Save member
         ASL A           ; Double it
         TAX             ; Index it
         LDY $6D,X       ; Actor's address
         BEQ C32CB8      ; Skip if nobody
         JSR C32C14      ; Valid target?
         BCC C32CB8      ; Skip if not
         LDA $0014,Y     ; Status LB
         STA $F8         ; Set target's
         LDA $0015,Y     ; Status HB
         STA $FB         ; Set target's
         JSR C32B39      ; Adjust HP, status
         JSR C32CCC      ; Get LV, Mag.Pwr
         LDA $AF         ; 1st valid target?
         BNE C32CB8      ; Branch if not
         JSR C30EE5      ; Play heal sound
         JSR C32CEA      ; Lower caster's MP
         INC $AF         ; Valid target: Y
C32CB8:  TDC             ; Clear A
         PLA             ; Member slot
         INC A           ; Member slot +1
         CMP #$04        ; Done all 4?
         BNE C32C90      ; Loop if not
         LDA $AF         ; Is any valid?
         BNE C32CC9      ; Branch if so
         JSR C30EC0      ; Play buzzer
         JSR C3305D      ; Pixelate screen
C32CC9:  JMP C32BDE      ; Redo GFX, test MP

; Load caster's Mag.Pwr and level (for C2/0009)
C32CCC:  JSR C32CDF      ; Define stats
         LDA $11A0       ; Mag.Pwr
         STA $11AE       ; Memorize it
         JSR C32D03      ; Actor's address
         LDA $0008,Y     ; Level
         STA $11AF       ; Memorize it
         RTS

; Load member's stats and properties with gear
C32CDF:  TDC             ; Clear A
         LDA $28         ; Member slot
         TAX             ; Index it
         LDA $69,X       ; Actor
         JSL $C20006     ; Load data
         RTS

; Decrease caster's MP
C32CEA:  JSR C32D13      ; Spell
         JSR C3510D      ; Define cost
         STX $E7         ; Memorize it
         JSR C32D03      ; Define Y
         REP #$20        ; 16-bit A
         LDA $000D,Y     ; Actor's MP
         SEC             ; Prepare SBC
         SBC $E7         ; Subtract cost
         STA $000D,Y     ; Save changes
         SEP #$20        ; 8-bit A
         RTS

; Get caster's SRAM block address
C32D03:  TDC             ; Clear A
         LDA $28         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         LDY $6D,X       ; SRAM address
         RTS

; Get target's SRAM block address
C32D0B:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
         ASL A           ; Double it
         TAX             ; Index it
         LDY $6D,X       ; SRAM address
         RTS

; Get selected spell
C32D13:  TDC             ; Clear A
         LDA $99         ; Spell slot
         TAX             ; Index it
         LDA $7E9D89,X   ; Spell
         RTS

; 3C: Return to Magic menu
C32D1C:  JSR C3352F      ; Reset/Stop stuff
         JSR C36A08      ; Set Win1 bounds
         LDA #$42        ; Allow back row
         TRB $45         ; And cursor memory
         STZ $4A         ; List scroll: 0
         STZ $49         ; Top BG1 WR row: 1
         JSR C34DBC      ; Set to shift text
         JSR C34C80      ; Draw menu, etc.
         JSR C307B0      ; Queue cursor OAM
         JSR C32130      ; Create scrollbar
         JSR C34B82      ; Load navig data
         LDA $8E         ; Old cursor column
         STA $4D         ; Set onscreen col
         LDY $8E         ; Old cursor loc
         STY $4F         ; Set as current
         LDA $90         ; Old scroll pos
         STA $4A         ; Set as current
         LDA $4A         ; ...
         STA $E0         ; Memorize it...
         LDA $50         ; List row
         SEC             ; Prepare SBC
         SBC $E0         ; Sub scroll pos
         STA $4E         ; Set cursor row
         JSR C34B8B      ; Relocate cursor
         JSR C32158      ; Draw spells, etc.
         JSR C351C6      ; Draw MP cost
         JSR C30E6E      ; Upload BG3 A+B
         JSR C31368      ; Refresh screen
         LDY $00         ; X: 0
         STY $35         ; Set BG1 X-Pos
         JSR C31B99      ; Queue desc anim
         LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         JSR C30EFD      ; Queue lists upload
         LDA #$1A        ; C3/27E2
         STA $27         ; Queue Magic menu
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         JMP C33541      ; BRT:1 + NMI

; 3D: Handle multitarget spell
C32D78:  LDA $08         ; No-autofire keys
         BIT #$10        ; Pushing R?
         BNE C32D90      ; Branch if so
         LDA $08         ; ...
         BIT #$20        ; Pushing L?
         BNE C32D90      ; Branch if so
         LDA $09         ; No-autofire keys
         BIT #$01        ; Pushing right?
         BNE C32D90      ; Branch if so
         LDA $09         ; ...
         BIT #$02        ; Pushing left?
         BEQ C32D9B      ; Branch if not
C32D90:  JSR C30EA3      ; Sound: Cursor
         JSR C32DB7      ; Swap cursors
         LDA #$3B        ; C3/2AAE
         STA $26         ; Next: One target
         RTS

; Fork: Handle A
C32D9B:  LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C32DA4      ; Branch if not
         JMP C32C86      ; Handle spell

; Fork: Handle B
C32DA4:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C32DB6      ; Exit if not
         JSR C30EA9      ; Sound: Cursor
         JSR C32DB7      ; Swap cursors
         LDA #$3C        ; C3/2D1C
         STA $27         ; Queue Magic menu
         STZ $26         ; Next: Fade-out
C32DB6:  RTS

; Revert to a single target for spell
C32DB7:  JSR C32F98      ; Preload nav data
         JSR C307B0      ; Queue cursor OAM
         LDA #$00        ; Min slot: 0
         LDY #C32FC0     ; C3/2FC0
         JSR C31173      ; Queue D-Pad fn
         JSR C311B0      ; Run anim queue
         LDA $5F         ; Old cursor row
         STA $4E         ; Set as current
         LDA #$08        ; Blinkers: Off
         TRB $46         ; Set menu flag
         RTS

; Swap actor info for switched members
C32DD1:  TDC             ; Clear A
         LDA $28         ; Chosen slot A
         TAX             ; Index it
         LDA $4B         ; Chosen slot B
         TAY             ; Index it
         LDA $75,X       ; A's party info
         STA $E0         ; Memorize it
         LDA $0075,Y     ; B's party info
         STA $75,X       ; Set as A's
         LDA $E0         ; A's party info
         STA $0075,Y     ; Set as B's
         LDA $69,X       ; A's actor ID
         STA $E0         ; Memorize it
         LDA $0069,Y     ; B's actor ID
         STA $69,X       ; Set as A's
         LDA $E0         ; A's actor ID
         STA $0069,Y     ; Set as B's
         TDC             ; Clear A
         LDA $28         ; Chosen slot A
         ASL A           ; Double it
         TAX             ; Index it
         LDA $4B         ; Chosen slot B
         ASL A           ; Double it
         TAY             ; Index it
         REP #$20        ; 16-bit A
         LDA $6D,X       ; A's data adr
         STA $E7         ; Memorize it
         LDA $006D,Y     ; B's data adr
         STA $6D,X       ; Set as A's
         LDA $E7         ; A's data adr
         STA $006D,Y     ; Set as B's
         SEP #$20        ; 8-bit A
         RTS

; Toggle member's row, set to shift portrait
C32E10:  TDC             ; Clear A
         LDA $28         ; Member slot
         TAX             ; Index it
         LDA $75,X       ; Party info
         STA $E0         ; Memorize it
         LDA $60,X       ; Queue index
         TAX             ; Index it
         LDA $E0         ; Party info
         BIT #$20        ; Front row?
         BEQ C32E29      ; Branch if so
         LDA #$20        ; Row: Front
         TRB $E0         ; Add to info
         LDA #$03        ; Shift: Right
         BRA C32E2F      ; Skip 3 lines
C32E29:  LDA #$20        ; Row: Back
         TSB $E0         ; Add to info
         LDA #$02        ; Shift: Left
C32E2F:  STA $7E3649,X   ; Set anim mode
         TDC             ; ...
         LDA $28         ; Member slot
         TAX             ; Index it
         LDA $E0         ; Party info
         STA $75,X       ; Set member's
         RTS

; Set to delete all portraits
C32E3C:  TDC             ; Clear A
         LDA $60         ; Queue index A
         TAX             ; Index it
         LDA #$FF        ; Null value
         STA $7E35C9,X   ; Face A: Off
         LDA $61         ; Queue index B
         TAX             ; Index it
         LDA #$FF        ; Null value
         STA $7E35C9,X   ; Face B: Off
         LDA $62         ; Queue index C
         TAX             ; Index it
         LDA #$FF        ; Null value
         STA $7E35C9,X   ; Face C: Off
         LDA $63         ; Queue index D
         TAX             ; Index it
         LDA #$FF        ; Null value
         STA $7E35C9,X   ; Face D: Off
         RTS

; Handle selection in main menu list
C32E62:  TDC             ; Clear A
         LDA $4B         ; Chosen menu
         STA $25         ; Set submenu
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C32E6C,X)  ; Handle choice

; Jump table for the above
C32E6C:  dw C32E86       ; Item
         dw C32E90       ; Skills
         dw C32E90       ; Equip
         dw C32E90       ; Relic
         dw C32E90       ; Status
         dw C32E7A       ; Config
         dw C32EAA       ; Save

; Invoke Config menu
C32E7A:  JSR C30EB2      ; Sound: Click
         STZ $5F         ; Cursor: Bat.Mode
         STZ $26         ; Next: Fade-out
         LDA #$0D        ; C3/1C7D
         STA $27         ; Queue Config
         RTS

; Invoke Item menu
C32E86:  JSR C30EB2      ; Sound: Click
         STZ $26         ; Next: Fade-out
         LDA #$07        ; C3/1AD6
         STA $27         ; Queue Item menu
         RTS

; Initialize portrait targeting with main menu command
C32E90:  JSR C30EB2      ; Sound: Click
         LDA #$02        ; List cursor: Off
         TRB $46         ; Set menu flag
         JSR C32F98      ; Preload nav data
         LDA #$00        ; Min slot: 0
         LDY #C32FC0     ; C3/2FC0
         JSR C31173      ; Queue D-Pad fn
         JSR C32F06      ; Create blinker
         LDA #$06        ; C3/1DE8
         STA $26         ; Next: Targeting
         RTS

; Invoke Save menu if allowed
C32EAA:  LDA $0201       ; Can save here?
         BPL C32EBF      ; Fail if not
         JSR C30EB2      ; Sound: Click
         STZ $26         ; Next: Fade-out
         LDA #$13        ; C3/1CA0
         STA $27         ; Queue Save menu
         STA $9E         ; Set root menu cmd
         LDA #$04        ; C3/1A8A
         STA $9F         ; Set main menu cmd
         RTS             ; Exit
C32EBF:  JSR C30EC0      ; Play buzzer
         JSR C3305D      ; Pixelate screen
         RTS

; Initiate shifting to Order menu
C32EC6:  LDA #$02        ; List cursor: Off
         TRB $46         ; Set menu flag
         JSR C32F98      ; Preload nav data
         LDA #$00        ; Min slot: 0
         LDY #C32FC0     ; C3/2FC0
         JSR C31173      ; Queue D-Pad fn
         LDA #$06        ; Frames: 6
         STA $20         ; Set scroll timer
         LDY #$FFF4      ; Speed: -12
         STY $9C         ; Set scroll speed
         LDA #$05        ; Blinker: Off
         TRB $46         ; Order cursor: Off
         LDA #$0F        ; C3/240C
         STA $27         ; Queue: Choice 1
         LDA #$65        ; C3/36E7
         STA $26         ; Next: Pan screen
         RTS

; Create blinking cursor for Espers menu
C32EEB:  LDA #$02        ; Min slot: 16
         LDY #C308D1     ; C3/08D1
         JSR C31173      ; Queue OAM fn
         REP #$20        ; 16-bit A
         LDA #$0038      ; X: 56
         STA $7E33CA,X   ; Set sprite's
         LDA #$0036      ; Y: 54
         STA $7E344A,X   ; Set sprite's
         SEP #$20        ; 8-bit A
         RTS

; Create blinking cursor to the right of main cursor
C32F06:  LDA #$02        ; Min slot: 16
         LDY #C307FF     ; C3/07FF
         JSR C31173      ; Queue OAM fn
         REP #$20        ; 16-bit A
         LDA $55         ; Cursor's X
         INC A           ; +1 px right
         INC A           ; +1 px right
         STA $7E33CA,X   ; Set blinker X
         LDA $57         ; Cursor's Y
         STA $7E344A,X   ; Set blinker Y
         SEP #$20        ; 8-bit A
         RTS

; Create blinking cursor to northeast of main cursor
C32F21:  LDA #$01        ; Min slot: 8
         LDY #C307FF     ; C3/07FF
         JSR C31173      ; Queue OAM fn
         REP #$20        ; 16-bit A
         LDA $55         ; Cursor's X
         CLC             ; Prepare ADC
         ADC #$0004      ; +4 px right
         STA $7E33CA,X   ; Set blinker X
         LDA $57         ; Cursor's Y
         SEC             ; Prepare SBC
         SBC #$0004      ; +4 px up
         STA $7E344A,X   ; Set blinker Y
         SEP #$20        ; 8-bit A
         RTS

; Update cursor position in main menu list
C32F42:  TAX             ; Index mode
         JMP (C32F46,X)  ; Handle mode

; Jump table for the above
C32F46:  dw C32F4A       ; Initialize data
         dw C32F6B       ; Update position

; Mode 0: Initialize data
C32F4A:  LDX $2D         ; Queue index
         LDA #$02        ; Show cursor: Y
         TSB $46         ; Set menu flag
         INC $3649,X     ; Mode +1
         LDY #C32F85     ; C3/2F85
         JSR C305FE      ; Load navig data
         LDA $1D4E       ; Game options
         AND #$40        ; Cursor memory?
         BEQ C32F65      ; Branch if not
         LDY $022B       ; Former position
         STY $4D         ; Set as current
C32F65:  LDY #C32F8A     ; C3/2F8A
         JSR C30640      ; Set cursor X/Y

; Mode 1: Update position
C32F6B:  LDA $46         ; Menu flags
         BIT #$02        ; Delete cursor?
         BEQ C32F83      ; Dequeue if so
         LDX $2D         ; Queue index
         JSR C3072D      ; Handle D-Pad
         LDY #C32F8A     ; C3/2F8A
         JSR C30640      ; Set cursor X/Y
         LDY $4D         ; Cursor position
         STY $022B       ; To cursor memory
         SEC             ; Set to requeue
         RTS             ; Exit
C32F83:  CLC             ; Set to dequeue
         RTS

; Navigation data for main menu
C32F85:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $07          ; 7 rows

; Cursor positions for main menu
C32F8A:  dw $12AF        ; Item
         dw $21AF        ; Skills
         dw $30AF        ; Equip
         dw $3FAF        ; Relic
         dw $4EAF        ; Status
         dw $5DAF        ; Config
         dw $6CAF        ; Save

; Preload nav data for portrait selection, disable empty slots
C32F98:  JSR C32FB1      ; Load navig data
         TDC             ; Clear A
         TAX             ; 1st: Member 1
         TAY             ; ...
C32F9E:  LDA $0069,X     ; Actor in slot
         BPL C32FAA      ; Skip if any
         PHX             ; Save slot
         TXA             ; Move it to A
         ASL A           ; Double it
         TAX             ; Reindex it
         STZ $85,X       ; Disable slot
         PLX             ; Member slot
C32FAA:  INX             ; Member slot +1
         CPX #$0004      ; Done all 4?
         BNE C32F9E      ; Loop if not
         RTS

; Preload navigation data for portrait selection
C32FB1:  LDX $00         ; Index: 0
C32FB3:  LDA.L C33042,X  ; Navig data
         STA $80,X       ; Save in RAM
         INX             ; Index +1
         CPX #$000D      ; At C3/304F?
         BNE C32FB3      ; Loop if not
         RTS

; Update movable cursor's position for portrait selection
C32FC0:  TAX             ; Index mode
         JMP (C32FC4,X)  ; Handle mode

; Jump table for the above
C32FC4:  dw C32FC8       ; Initialize data
         dw C33014       ; Update position

; Mode 0: Initialize data
C32FC8:  LDX $2D         ; Queue index
         LDA #$14        ; Main cursor: On
         TSB $46         ; Enable D-Pad
         INC $3649,X     ; Mode +1
         JSR C32FF5      ; Load navig data
         LDA $45         ; Menu flags
         BIT #$40        ; Skip cursor mem?
         BNE C32FE6      ; Branch if so
         LDA $1D4E       ; Game options
         AND #$40        ; Cursor memory?
         BEQ C32FE6      ; Branch if not
         LDY $022D       ; Former position
         STY $4D         ; Set as current
C32FE6:  JSR C33008      ; Relocate cursor
         LDA $55         ; On empty slot?
         BNE C32FF3      ; Exit if not
         JSR C32FF5      ; Target leader
         JSR C33008      ; Relocate cursor
C32FF3:  SEC             ; Set to requeue
         RTS

; Load custom nav data for portrait selection, target leader
C32FF5:  LDY #$0080      ; ...
         JSR C305FE      ; ...
         LDY #$0080      ; 00/0080
         LDA #$00        ; Bank: 00
         STA $ED         ; Set source HB
         JSR C30602      ; Load navig data
         JMP C3061E      ; Target leader

; Set portrait cursor's slot and base pixel position
C33008:  LDY #$0085      ; 00/0085
         STY $E7         ; Set src LBs
         LDA #$00        ; Bank: 00
         STA $E9         ; Set src HB
         JMP C30643      ; Relocate cursor

; Mode 1: Update position
C33014:  LDA $45         ; Menu flags
         BIT #$40        ; Skip cursor mem?
         BNE C3301F      ; Branch if so
         LDY $4D         ; Cursor position
         STY $022D       ; To cursor memory
C3301F:  LDA $46         ; Menu flags
         BIT #$04        ; Delete cursor?
         BEQ C33040      ; Dequeue if so
         BIT #$10        ; Swapping chars?
         BEQ C3303E      ; Exit if so
         LDX $2D         ; Queue index
C3302B:  JSR C3072D      ; Handle D-Pad
         LDY #$0085      ; 00/0085
         STY $E7         ; Set src LBs
         LDA #$00        ; Bank: 00
         STA $E9         ; Set src HB
         JSR C30643      ; Relocate cursor
         LDA $55         ; On empty slot?
         BEQ C3302B      ; Retarget if so
C3303E:  SEC             ; Set to requeue
         RTS             ; Exit
C33040:  CLC             ; Set to dequeue
         RTS

; Navigation data for portrait selection
C33042:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $04          ; 4 rows

; Cursor positions for portrait selection
C33047:  dw $2808        ; Member 1
         dw $5808        ; Member 2
         dw $8808        ; Member 3
         dw $B808        ; Member 4

; Queue menu fade-out
C3304F:  TDC             ; Min slot: 0
         LDY #C3309F     ; C3/309F
         JMP C31173      ; Put in queue

; Queue menu fade-in
C33056:  TDC             ; Min slot: 0
         LDY #C330CA     ; C3/30CA
         JMP C31173      ; Put in queue

; Queue mosaic effect
C3305D:  TDC             ; Min slot: 0
         LDY #C33064     ; C3/3064
         JMP C31173      ; Put in queue

; Process queued mosaic effect
C33064:  TAX             ; Index mode
         JMP (C33068,X)  ; Handle mode

; Jump table for the above
C33068:  dw C3306C       ; Initialize mosaic
         dw C33079       ; Sustain mosaic

; Mode 0: Initialize mosaic
C3306C:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         STZ $33CA,X     ; 1st: C3/3097
         LDA #$08        ; Frames: 8
         STA $3349,X     ; Set timer

; Mode 1: Sustain mosaic
C33079:  LDX $2D         ; Queue index
         LDA $3349,X     ; Timer expired?
         BEQ C33095      ; Dequeue if so
         TDC             ; ...
         LDA $33CA,X     ; Table index
         TAX             ; Index it
         LDA.L C33097,X  ; Parameters
         STA $B5         ; Save in RAM
         LDX $2D         ; Queue index
         INC $33CA,X     ; Table index +1
         DEC $3349,X     ; Timer -1
         SEC             ; Set to requeue
         RTS             ; Exit
C33095:  CLC             ; Set to dequeue
         RTS

; Mosaic parameters
C33097:  db $17          ; Intensity 1 for BG1-BG3
C33098:  db $27          ; Intensity 2 for BG1-BG3
C33099:  db $37          ; Intensity 3 for BG1-BG3
C3309A:  db $47          ; Intensity 4 for BG1-BG3
C3309B:  db $37          ; Intensity 3 for BG1-BG3
C3309C:  db $27          ; Intensity 2 for BG1-BG3
C3309D:  db $17          ; Intensity 1 for BG1-BG3
C3309E:  db $07          ; Intensity 0 for BG1-BG3

; Process queued menu fade-out
C3309F:  TAX             ; Index mode
         JMP (C330A3,X)  ; Handle mode

; Jump table for the above
C330A3:  dw C330A7       ; Initialize brightness
         dw C330B1       ; Decrease brightness

; Mode 0: Initialize brightness
C330A7:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         LDA #$0F        ; BRT: 15 and ON
         STA $33CA,X     ; Set next BRT

; Mode 1: Decrease brightness
C330B1:  LDY $20         ; Timer expired?
         BEQ C330C4      ; Finalize if so
         LDX $2D         ; Queue index
         LDA $33CA,X     ; Next brightness
         STA $44         ; Set as current
         DEC $33CA,X     ; Next BRT -1
         DEC $33CA,X     ; Next BRT -1
         SEC             ; Set to requeue
         RTS             ; Exit
C330C4:  LDA #$01        ; BRT: 1 and ON
         STA $44         ; Set brightness
         CLC             ; Set to dequeue
         RTS

; Process queued menu fade-in
C330CA:  TAX             ; Index mode
         JMP (C330CE,X)  ; Handle mode

; Jump table for the above
C330CE:  dw C330D2       ; Initialize brightness
         dw C330DC       ; Increase brightness

; Mode 0: Initialize brightness
C330D2:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         LDA #$01        ; BRT: 1 and ON
         STA $344A,X     ; Set next BRT

; Mode 1: Increase brightness
C330DC:  LDY $20         ; Timer expired?
         BEQ C330EF      ; Finalize if so
         LDX $2D         ; Queue index
         LDA $344A,X     ; Next brightness
         STA $44         ; Set as current
         INC $344A,X     ; Next BRT +1
         INC $344A,X     ; Next BRT +1
         SEC             ; Set to requeue
         RTS             ; Exit
C330EF:  LDA #$0F        ; BRT: 15 and ON
         STA $44         ; Set brightness
         CLC             ; Set to dequeue
         RTS

; Draw and upload main menu
C330F5:  JSR C33F99      ; Apply user font
         JSR C36A28      ; Clear BG2 map A
         JSR C36A2D      ; Clear BG2 map B
         JSR C36A19      ; Clear BG1 map B
         JSR C36A41      ; Clear BG3 map B
         LDY #C331CF     ; C3/31CF
         JSR C30341      ; Draw Order box A
         LDY #C331D3     ; C3/31D3
         JSR C30341      ; Draw Order box B
         LDY #C331C7     ; C3/31C7
         JSR C30341      ; Draw main window
         LDY #C331BB     ; C3/31BB
         JSR C30341      ; Draw option box
         JSR C33170      ; Draw stats, etc.
         JSR C3326C      ; Draw time
         JSR C331F3      ; Draw menu list
         JMP C3319F      ; Upload text maps

; Draw and upload save confirmation menu
C33128:  JSR C33F99      ; Apply user font
         JSR C36E82      ; Load portraits
         JSR C36C09      ; And their colors
         JSR C331A8      ; Upload skin
         LDY #C331C7     ; C3/31C7
         JSR C30341      ; Draw main window
         LDY #C331CB     ; C3/31CB
         JSR C30341      ; Draw Yes/No box
         JSR C33170      ; Draw stats, etc.
         JSR C33295      ; Draw time
         JSR C331D7      ; Draw question
         JMP C3319F      ; Upload text maps

; Draw and upload load confirmation menu
C3314C:  JSR C33F99      ; Apply user font
         JSR C36E82      ; Load portraits
         JSR C36C09      ; And their colors
         JSR C331A8      ; Upload skin
         LDY #C331C7     ; C3/31C7
         JSR C30341      ; Draw main window
         LDY #C331CB     ; C3/31CB
         JSR C30341      ; Draw Yes/No box
         JSR C33170      ; Draw stats, etc.
         JSR C33295      ; Draw time
         JSR C331E5      ; Draw question
         JMP C3319F      ; Upload text maps

; Draw elements shared by main menu and save file submenus
C33170:  TDC             ; Gradient set: 0
         JSL $D4CA1D     ; Create gradient
         LDY #C331BF     ; C3/31BF
         JSR C30341      ; Draw time window
         LDY #C331C3     ; C3/31C3
         JSR C30341      ; Draw steps window
         JSR C30E52      ; Upload windows
         JSR C3318A      ; Draw party info
         JMP C33221      ; Draw game stats

; Draw party info
C3318A:  JSR C36A15      ; Clear BG1 map A
         JSR C36A3C      ; Clear BG3 map A
         JSR C36A46      ; Clear BG3 map C
C33193:  JSR C332F1      ; Handle member 1
         JSR C3333D      ; Handle member 2
         JSR C33389      ; Handle member 3
         JMP C333D5      ; Handle member 4

; Upload text tilemaps for menu with portraits
C3319F:  JSR C30E28      ; Upload BG1 A+B
         JSR C30E6E      ; Upload BG3 A+B
         JMP C30E7C      ; Upload BG3 C+D

; Upload skin for viewed save file
C331A8:  LDA $66         ; File viewed
         CMP #$01        ; File 1?
         BEQ C331B5      ; Branch if so
         CMP #$02        ; File 2?
         BEQ C331B8      ; Branch if so
         JMP C33AD9      ; Handle file 3
C331B5:  JMP C33AA1      ; Handle file 1
C331B8:  JMP C33ABD      ; Handle file 2

; Window layout for main menu and save file submenus
C331BB:  dw $58B7,$0D06  ; 08x15 at $58B7 (Options)
C331BF:  dw $5C77,$0206  ; 08x04 at $5C77 (Time)
C331C3:  dw $5D75,$0507  ; 09x07 at $5D75 (Steps)
C331C7:  dw $588B,$181C  ; 30x26 at $588B (Party)
C331CB:  dw $58B5,$0A07  ; 09x12 at $58B5 (Yes/No)
C331CF:  dw $60B9,$0207  ; 09x04 at $60B9 (Order; L part)
C331D3:  dw $5885,$0201  ; 03x04 at $5885 (Order; R part)

; Draw confirmation text for Save menu
C331D7:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDX #C33765     ; Text ptrs loc
         LDY #$000A      ; Strings: 5
         JSR C369BA      ; Draw text
         RTS

; Draw confirmation text for Load menu
C331E5:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDX #C3375D     ; Text ptrs loc
         LDY #$0008      ; Strings: 4
         JSR C369BA      ; Draw text
         RTS

; Draw list of submenus in main menu
C331F3:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDX #C33729     ; Text ptrs loc
         LDY #$0008      ; Strings: 4
         JSR C369BA      ; Do Item..Status
         LDA #$20        ; ...
         STA $29         ; ...
         LDX #C33759     ; Text ptrs loc
         LDY #$0004      ; Strings: 2
         JSR C369BA      ; Do Equip/Config
         LDA $0201       ; Can save here?
         BPL C33216      ; Branch if not
         LDA #$20        ; Color: User's
         BRA C33218      ; Skip a line
C33216:  LDA #$24        ; Color: Gray
C33218:  STA $29         ; Set palette
         LDY #C337FD     ; Text pointer
         JSR C302F9      ; Draw "Save"
         RTS

; Draw most text in small windows of main menu or save file submenu
C33221:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDY #C3380B     ; Text pointer
         JSR C302F9      ; Draw ":"
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         LDX #C33723     ; Text ptrs loc
         LDY #$0006      ; Strings: 3
         JSR C369BA      ; Draw SE titles
         LDY #C33817     ; Text pointer
         JSR C302F9      ; Draw "Gp"
         JSR C332CE      ; Cap GP
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDY $1866       ; Steps LBs
         STY $F1         ; Memorize them
         LDA $1868       ; Steps HB
         STA $F3         ; Memorize it
         JSR C30582      ; Turn into text
         LDX #$7DF7      ; Text position
         JSR C304AC      ; Draw step count
         LDY $1860       ; Gold LBs
         STY $F1         ; Memorize them
         LDA $1862       ; Gold HB
         STA $F3         ; Memorize it
         JSR C30582      ; Turn into text
         LDX #$7EB7      ; Text position
         JSR C304AC      ; Draw GP total
         RTS

; Draw time in main menu
C3326C:  LDA $1188       ; Timer 0 flags
         BIT #$10        ; Override clock?
         BEQ C33289      ; Branch if not
         LDY $1189       ; Countdown timer
         JSR C332B2      ; Divide by 60
         JSR C332B2      ; Divide by 60
         LDA $E7         ; Minutes
         STA $1863       ; Set shown hours
         LDA $4216       ; Seconds
         STA $1864       ; Set shown mins
         BRA C33295      ; Draw time

; Fork: Normal clock
C33289:  LDY $021B       ; Hours, mins
         STY $1863       ; Save in SRAM
         LDA $021D       ; Seconds
         STA $1865       ; Save in SRAM

; Fork: Draw time
C33295:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDA $1863       ; Shown hours
         JSR C304E0      ; Turn into text
         LDX #$7CFB      ; Text position
         JSR C304B6      ; Draw 2 digits
         LDA $1864       ; Shown minutes
         JSR C304F9      ; Turn into text
         LDX #$7D01      ; Text position
         JSR C304B6      ; Draw 2 digits
         RTS

; Divide countdown timer's value by 60
C332B2:  STY $4204       ; Set dividend
         LDA #$3C        ; 60
         STA $4206       ; Set divisor
         NOP
         NOP
         NOP
         NOP
         NOP
         NOP
         NOP
         NOP
         NOP
         NOP
         NOP
         NOP
         NOP
         NOP
         LDY $4214       ; Quotient
         STY $E7         ; Memorize it
         RTS

; Enforce GP cap
C332CE:  LDA #$7F        ; Cap LB
         CMP $1860       ; C- if < GP LB
         LDA #$96        ; Cap MB
         SBC $1861       ; Deduct GP w/ C
         LDA #$98        ; Cap HB
         SBC $1862       ; Deduct GP w/ C
         BCS C332EA      ; Exit if < 10M
         LDY #$967F      ; Cap LBs
         STY $1860       ; Set gold LBs
         LDA #$98        ; Cap HB
         STA $1862       ; Set gold HB
C332EA:  RTS

; Hi-fork: Hide portrait
C332EB:  JSR C30A22      ; Init portrait
         JMP C3341B      ; Hide portrait

; Draw info for member 1
C332F1:  LDA $69         ; Nobody here?
         BMI C332EB      ; Abort if so
         LDX $6D         ; Actor's address
         STX $67         ; Memorize it
         LDA #$24        ; Palette 1
         STA $29         ; Color: Blue
         LDX #C33741     ; Text ptrs loc
         LDY #$0006      ; Strings: 3
         JSR C369BA      ; Draw "LV/HP/MP"
         LDY #$3927      ; Class/KO pos
         LDX #$1578      ; Icon position
         STZ $48         ; Anim mode: 0
         JSR C33427      ; Display status
         LDX #C33731     ; Text ptrs loc
         STX $F1         ; ...
         LDY #$0004      ; Strings: 2
         STY $EF         ; ...
         JSR C369BA      ; Draw both "/"
         LDY #$3919      ; Text position
         JSR C334CF      ; Draw actor name
         LDX #C3332D     ; Coords tbl ptr
         JSR C30C6C      ; Draw LV, HP, MP
         JMP C30A22      ; Create portrait

; Tilemap pointers for stats of member 1
C3332D:  dw $39A7        ; Level
         dw $39E3        ; HP
         dw $39ED        ; Max HP
         dw $3A23        ; MP
         dw $3A2D        ; Max MP

; Hi-fork: Hide portrait
C33337:  JSR C30A4B      ; Init portrait
         JMP C3341B      ; Hide portrait

; Draw info for member 2
C3333D:  LDA $6A         ; Nobody here?
         BMI C33337      ; Abort if so
         LDX $6F         ; Actor's address
         STX $67         ; Memorize it
         LDA #$24        ; Palette 1
         STA $29         ; Color: Blue
         LDX #C33747     ; Text ptrs loc
         LDY #$0006      ; Strings: 3
         JSR C369BA      ; Draw "LV/HP/MP"
         LDY #$3AA7      ; Class/KO pos
         LDX #$4578      ; Icon position
         STZ $48         ; Anim mode: 0
         JSR C33427      ; Display status
         LDX #C33735     ; Text ptrs loc
         STX $F1         ; ...
         LDY #$0004      ; Strings: 2
         STY $EF         ; ...
         JSR C369BA      ; Draw both "/"
         LDY #$3A99      ; Text position
         JSR C334CF      ; Draw actor name
         LDX #C33379     ; Coords tbl ptr
         JSR C30C6C      ; Draw LV, HP, MP
         JMP C30A4B      ; Create portrait

; Tilemap pointers for stats of member 2
C33379:  dw $3B27        ; Level
         dw $3B63        ; HP
         dw $3B6D        ; Max HP
         dw $3BA3        ; MP
         dw $3BAD        ; Max MP

; Hi-fork: Hide portrait
C33383:  JSR C30A76      ; Init portrait
         JMP C3341B      ; Hide portrait

; Draw info for member 3
C33389:  LDA $6B         ; Nobody here?
         BMI C33383      ; Abort if so
         LDX $71         ; Actor's address
         STX $67         ; Memorize it
         LDA #$24        ; Palette 1
         STA $29         ; Color: Blue
         LDX #C3374D     ; Text ptrs loc
         LDY #$0006      ; Strings: 3
         JSR C369BA      ; Draw "LV/HP/MP"
         LDY #$3C27      ; Class/KO pos
         LDX #$7578      ; Icon position
         STZ $48         ; Anim mode: 0
         JSR C33427      ; Display status
         LDX #C33739     ; Text ptrs loc
         STX $F1         ; ...
         LDY #$0004      ; Strings: 2
         STY $EF         ; ...
         JSR C369BA      ; Draw both "/"
         LDY #$3C19      ; Text position
         JSR C334CF      ; Draw actor name
         LDX #C333C5     ; Coords tbl ptr
         JSR C30C6C      ; Draw LV, HP, MP
         JMP C30A76      ; Create portrait

; Tilemap pointers for stats of member 3
C333C5:  dw $3CA7        ; Level
         dw $3CE3        ; HP
         dw $3CED        ; Max HP
         dw $3D23        ; MP
         dw $3D2D        ; Max MP

; Hi-fork: Hide portrait
C333CF:  JSR C30AA1      ; Init portrait
         JMP C3341B      ; Hide portrait

; Draw info for member 4
C333D5:  LDA $6C         ; Nobody here?
         BMI C333CF      ; Abort if so
         LDX $73         ; Actor's address
         STX $67         ; Memorize it
         LDA #$24        ; Palette 1
         STA $29         ; Color: Blue
         LDX #C33753     ; Text ptrs loc
         LDY #$0006      ; Strings: 3
         JSR C369BA      ; Draw "LV/HP/MP"
         LDY #$3DA7      ; Class/KO pos
         LDX #$A578      ; Icon position
         STZ $48         ; Anim mode: 0
         JSR C33427      ; Display status
         LDX #C3373D     ; Text ptrs loc
         STX $F1         ; ...
         LDY #$0004      ; Strings: 2
         STY $EF         ; ...
         JSR C369BA      ; Draw both "/"
         LDY #$3D99      ; Text position
         JSR C334CF      ; Draw actor name
         LDX #C33411     ; Coords tbl ptr
         JSR C30C6C      ; Draw LV, HP, MP
         JMP C30AA1      ; Create portrait

; Tilemap pointers for stats of member 4
C33411:  dw $3E27        ; Level
         dw $3E63        ; HP
         dw $3E6D        ; Max HP
         dw $3EA3        ; MP
         dw $3EAD        ; Max MP

; Hide portrait for vacant member slot
C3341B:  REP #$20        ; 16-bit A
         LDA #$00D8      ; Base Y: 216
         STA $7E344A,X   ; Set sprite's
         SEP #$20        ; 8-bit A
         RTS

; Display actor's status (excludes Status menu)
C33427:  STX $E7         ; Save icon pos
         JSR C33519      ; Set text pos
         LDA $0014,Y     ; Wounded?
         BMI C334B0      ; Draw it if so
         AND #$70        ; Clear/Imp/Pet
         STA $E1         ; Memorize them
         LDA $0014,Y     ; Status LB
         AND #$07        ; Dark/Zom/Poison
         ASL A           ; Put in bits 1-3
         STA $E2         ; Memorize them
         LDA $0015,Y     ; Status HB
         AND #$80        ; Isolate Float
         ORA $E1         ; Add Clear, etc.
         ORA $E2         ; Add Dark, etc.
         STA $E1         ; ...
         BEQ C334A9      ; Exit if none
         STZ $F1         ; Sprite index LB
         STZ $F2         ; Sprite index HB
         LDX #$0007      ; Status left: 7
C33451:  PHX             ; Save counter
         ASL A           ; Got current?
         BCC C3349C      ; Skip if not
         PHA             ; Save status
         LDA #$03        ; Min slot: 24
         LDY #C37B42     ; C3/7B42
         JSR C31173      ; Queue icon OAM
         LDA #$01        ; Pans with BG1
         STA $7E364A,X   ; Set OBJ flags
         LDA $48         ; Anim mode
         STA $7E3649,X   ; Set icon's
         TXY             ; Queue index
         LDX $F1         ; Sprite index
         PHB             ; Save DB
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         REP #$20        ; 16-bit A
         LDA $D8EC25,X   ; Anim table ptr
         STA $32C9,Y     ; Set icon's
         SEP #$20        ; 8-bit A
         LDA $E7         ; X position
         STA $33CA,Y     ; Set icon's
         LDA $E8         ; Y position
         STA $344A,Y     ; Set icon's
         TDC             ; Clear A
         STA $33CB,Y     ; No use...
         STA $344B,Y     ; No use...
         LDA #$D8        ; Bank: D8
         STA $35CA,Y     ; Set ptr HB
         PLB             ; Restore DB
         CLC             ; Prepare ADC
         LDA #$0A        ; Modifier: 10
         ADC $E7         ; Add current X
         STA $E7         ; Set current X
         PLA             ; Statuses
C3349C:  INC $F1         ; Sprite index +1
         INC $F1         ; Sprite index +1
         PLX             ; Statuses left
         DEX             ; One less left
         BNE C33451      ; Loop till last
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         RTS             ; ^ For stats

; Fork: Draw actor class (SFC)
C334A9:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         JMP C334E5      ; RTS...

; Fork: Draw "Wounded"
C334B0:  LDX #$9E8B      ; 7E/9E8B
         STX $2181       ; Set WRAM LBs
         LDX $00         ; Index: 0
C334B8:  LDA.L C3371B,X  ; Letter
         STA $2180       ; Add to string
         INX             ; Point to next
         CPX #$0008      ; Copied 8?
         BNE C334B8      ; Loop if not
         STZ $2180       ; End string
         LDA #$28        ; Palette 2
         STA $29         ; Color: Gray
         JMP C37FD9      ; Draw string

; Draw actor name
C334CF:  JSR C33519      ; Set pos/WRAM/Y
C334D2:  LDX #$0006      ; Letters: 6
C334D5:  LDA $0002,Y     ; Letter
         STA $2180       ; Add to string
         INY             ; Point to next
         DEX             ; One less left
         BNE C334D5      ; Loop till last
         STZ $2180       ; End string
         JMP C37FD9      ; Draw string

; Draw actor class (SFC)
C334E5:  RTS             ; ...

; Draw equipped esper
C334E6:  JSR C33519      ; Set pos/WRAM/Y
         LDA $001E,Y     ; Actor's esper
         CMP #$FF        ; None?
         BEQ C33508      ; Blank if so
         ASL A           ; x2
         ASL A           ; x4
         ASL A           ; x8
         TAX             ; Index it
         LDY #$0008      ; Letters: 8
C334F7:  LDA $E6F6E1,X   ; Letter
         STA $2180       ; Add to string
         INX             ; Point to next
         DEY             ; One less left
         BNE C334F7      ; Loop till last
         STZ $2180       ; End string
         JMP C37FD9      ; Draw string

; Fork: Blank esper name
C33508:  LDY #$0008      ; Letters: 8
         LDA #$FF        ; Space char
C3350D:  STA $2180       ; Add to string
         DEY             ; One less left
         BNE C3350D      ; Loop till last
         STZ $2180       ; End string
         JMP C37FD9      ; Draw string

; Prepare name drawing
C33519:  LDX #$9E89      ; 7E/9E89
         STX $2181       ; Set WRAM LBs
         REP #$20        ; 16-bit A
         TYA             ; Tilemap ptr
         SEP #$20        ; 8-bit A
         STA $2180       ; Set position LB
         XBA             ; Switch to HB
         STA $2180       ; Set position HB
         TDC             ; Clear A
         LDY $67         ; Actor address
         RTS

; Reset OAM and anim queue; disable screen, interrupts, pad, HDMA
C3352F:  LDA #$80        ; BRT:0 and OFF
         STA $2100       ; Disable screen
         JSR C31114      ; Reset OAM, queue
         STZ $4200       ; Disable INT, pad
         STZ $420B       ; Disable DMA...
         STZ $420C       ; Disable HDMA
         RTS

; Prepare fade-in
C33541:  LDA #$01        ; BRT: 1 and ON
         STA $44         ; Set brightness
         JMP C31368      ; Refresh screen

; Redraw time in main menu
C33548:  JSR C30F39      ; Queue BG3 upload
         JMP C3326C      ; Draw time

; Queue main screen designation HDMA for main menu
C3354E:  LDX $00         ; Index: 0
         LDA #$17        ; BG1-3, sprites
C33552:  STA $7E9A09,X   ; Set MS desig.
         INX             ; Index +1
         CPX #$00DF      ; At 7E/9AE8?
         BNE C33552      ; Loop if not
         LDA #$40        ; 1Rx1B via ptrs
         STA $4360       ; Set DMA mode
         LDA #$2C        ; $212C
         STA $4361       ; To MS desig.
         LDY #C3357B     ; C3/357B
         STY $4362       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4364       ; Set src HB
         LDA #$7E        ; Bank: 7E
         STA $4367       ; Set indir HB
         LDA #$40        ; Channel: 6
         TSB $43         ; Queue HDMA-6
         RTS

; Main screen designation table for main menu
C3357B:  db $F0,$09,$9A  ; 112 lines, use $9A09
         db $F0,$79,$9A  ; 112 lines, use $9A79
         db $00          ; End

; Queue member swap animation for Order menu
C33582:  LDA $28         ; First choice
         CMP $4B         ; Above second?
         BCC C3359D      ; Branch if so
         LDA #$03        ; Min slot: 24
         LDY #C335D4     ; C3/35D4
         JSR C31173      ; Queue B's anim
         JSR C335C1      ; Set slot B's Y
         LDA #$03        ; Min slot: 24
         LDY #C3361F     ; C3/361F
         JSR C31173      ; Queue A's anim
         BRA C335B2      ; Set slot A's Y

; Fork: First choice is above second
C3359D:  LDA #$03        ; Min slot: 24
         LDY #C335D4     ; C3/35D4
         JSR C31173      ; Queue A's anim
         JSR C335B2      ; Set slot A's Y
         LDA #$03        ; Min slot: 24
         LDY #C3361F     ; C3/361F
         JSR C31173      ; Queue B's anim
         BRA C335C1      ; Set slot B's Y

; Fork: Set base scanline for slot A
C335B2:  TXY             ; Queue index
         TDC             ; Clear A
         LDA $28         ; Chosen slot A
         TAX             ; Index it
         LDA.L C335D0,X  ; Base scanline
         TYX             ; Queue index
         STA $7E33CA,X   ; Put in queue
         RTS

; Fork: Set base scanline for slot B
C335C1:  TXY             ; Queue index
         TDC             ; Clear A
         LDA $4B         ; Chosen slot B
         TAX             ; Index it
         LDA.L C335D0,X  ; Base scanline
         TYX             ; Queue index
         STA $7E33CA,X   ; Put in queue
         RTS

; Base scanlines for member swap animation
C335D0:  db $0D          ; Member slot 1
         db $3D          ; Member slot 2
         db $6D          ; Member slot 3
         db $9D          ; Member slot 4

; Erase member slot contents from the top down, and vice versa
C335D4:  TAX             ; Index mode
         JMP (C335D8,X)  ; Handle mode

; Jump table for the above
C335D8:  dw C335DE       ; Pointless...
         dw C335E3       ; Erase 4 lines
         dw C33602       ; Print 4 lines

; Mode 0: Erase 4 lines, advance mode...
C335DE:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1

; Mode 1: Erase 4 lines
C335E3:  LDY $2D         ; Queue index
         LDA $22         ; Time left
         CMP #$0C        ; 12 frames?
         BEQ C335FA      ; Unmask if so
         TDC             ; Clear A
         LDA $33CA,Y     ; Scanline
         TAX             ; Index it
         LDA #$06        ; On MS: BG2+BG3
         JSR C33677      ; Hide 4 lines
         STA $33CA,Y     ; Save scanline
         SEC             ; Set to requeue
         RTS

; Fork: Start unmasking
C335FA:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         DEC $33CA,X     ; Scanline -1

; Mode 2: Print 4 lines
C33602:  LDA $45         ; Menu flags
         BIT #$08        ; Got go-signal?
         BEQ C3361B      ; Exit if not
         LDY $2D         ; Queue index
         LDA $22         ; Timer expired?
         BEQ C3361D      ; Dequeue if so
         TDC             ; Clear A
         LDA $33CA,Y     ; Scanline
         TAX             ; Index it
         LDA #$17        ; On MS: BGs+OBJ
         JSR C3368D      ; Unhide 4 lines
         STA $33CA,Y     ; Save scanline
C3361B:  SEC             ; Set to requeue
         RTS             ; Exit
C3361D:  CLC             ; Set to dequeue
         RTS

; Erase member slot contents from the bottom up, and vice versa
C3361F:  TAX             ; Index mode
         JMP (C33623,X)  ; Handle mode

; Jump table for the above
C33623:  dw C33629       ; Start from bottom
         dw C33637       ; Erase 4 lines
         dw C33658       ; Print 4 lines

; Mode 0: Start from bottom
C33629:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         LDA $33CA,X     ; Top scanline
         CLC             ; Prepare ADC
         ADC #$2F        ; Go 47 px down
         STA $33CA,X     ; Save changes

; Mode 1: Erase 4 lines
C33637:  LDY $2D         ; Queue index
         LDA $22         ; Time left
         CMP #$0C        ; 12 frames?
         BEQ C33650      ; Unmask if so
         TDC             ; Clear A
         LDA $33CA,Y     ; Scanline
         TAX             ; Index it
         LDA #$06        ; On MS: BG2+BG3
         JSR C3368D      ; Hide 4 lines
         STA $33CA,Y     ; Save scanline
         DEC $22         ; Anim timer -1
         SEC             ; Set to requeue
         RTS

; Fork: Start ummasking
C33650:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         INC $33CA,X     ; Scanline +1

; Mode 2: Print 4 lines
C33658:  LDA $45         ; Menu flags
         BIT #$08        ; Got go-signal?
         BEQ C33673      ; Exit if not
         LDY $2D         ; Queue index
         LDA $22         ; Timer expired?
         BEQ C33675      ; Dequeue if so
         TDC             ; Clear A
         LDA $33CA,Y     ; Scanline
         TAX             ; Index it
         LDA #$17        ; On MS: BGs+OBJ
         JSR C33677      ; Unhide 4 lines
         STA $33CA,Y     ; Save scanline
         DEC $22         ; Anim timer -1
C33673:  SEC             ; Set to requeue
         RTS             ; Exit
C33675:  CLC             ; Set to dequeue
         RTS

; Enable or disable desired layers on next 4 lines below
C33677:  STA $7E9A09,X   ; MS desig L1
         INX             ; Scanline +1
         STA $7E9A09,X   ; MS desig L2
         INX             ; Scanline +1
         STA $7E9A09,X   ; MS desig L3
         INX             ; Scanline +1
         STA $7E9A09,X   ; MS desig L4
         INX             ; Scanline +1
         TXA             ; Line number
         RTS

; Enable or disable desired layers on next 4 lines above
C3368D:  STA $7E9A09,X   ; MS desig L4
         DEX             ; Scanline -1
         STA $7E9A09,X   ; MS desig L3
         DEX             ; Scanline -1
         STA $7E9A09,X   ; MS desig L2
         DEX             ; Scanline -1
         STA $7E9A09,X   ; MS desig L1
         DEX             ; Scanline -1
         TXA             ; Line number
         RTS

; Set to condense BG3 text in main menu
C336A3:  LDA #$02        ; 1Rx2B to PPU
         STA $4350       ; Set DMA mode
         LDA #$12        ; $2112
         STA $4351       ; To BG3 V-Scroll
         LDY #C336C2     ; C3/36C2
         STY $4352       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4354       ; Set src HB
         LDA #$C3        ; ...
         STA $4357       ; Set indir HB
         LDA #$20        ; Channel: 5
         TSB $43         ; Queue HDMA-5
         RTS

; Text shifting table for the above
C336C2:  db $0F,$00,$00  ; Nothing
         db $0F,$03,$00  ; Item
         db $0F,$04,$00  ; Skills
         db $0F,$05,$00  ; Equip
         db $0F,$06,$00  ; Relic
         db $0F,$07,$00  ; Status
         db $0F,$08,$00  ; Config
         db $0F,$09,$00  ; Save
         db $07,$08,$00  ; Nothing
         db $08,$00,$00  ; Nothing
         db $08,$00,$00  ; Time
         db $18,$00,$00  ; The rest
         db $00          ; End

; 65: Shift screen left or right
C336E7:  LDA $20         ; Timer expired?
         BNE C336EF      ; Branch if not
         LDA $27         ; Queued command
         STA $26         ; Execute it next
C336EF:  REP #$20        ; 16-bit A
         LDA $35         ; BG1 X-Pos
         CLC             ; Prepare ADC
         ADC $9C         ; Add scroll speed
         STA $35         ; Set BG1 X-Pos
         STA $39         ; Set BG2 X-Pos
         STA $3D         ; Set BG3 X-Pos
         SEP #$20        ; 8-bit A
         RTS

; Load navigation data for non-shifted Status menu
C336FF:  LDY #C3370E     ; C3/370E
         JMP C305FE      ; Load navig data

; Handle D-Pad for non-shifted Status menu
C33705:  JSR C3072D      ; Handle D-Pad
C33708:  LDY #C33713     ; C3/3713
         JMP C30640      ; Relocate cursor

; Navigation data for non-shifted Status menu
C3370E:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $04          ; 4 rows

; Cursor positions for non-shifted Status menu
C33713:  dw $5990        ; Command 1
         dw $6590        ; Command 2
         dw $7190        ; Command 3
         dw $7D90        ; Command 4

; Text, "Wounded "
C3371B:  db "Wounded "

; Text pointers for main menu and save file submenus
C33723:  dw C33804       ; Time
C33725:  dw C3380F       ; Steps
C33727:  dw C33850       ; Order
C33729:  dw C337CB       ; Item
C3372B:  dw C337D2       ; Skills
C3372D:  dw C337E3       ; Relic
C3372F:  dw C337EB       ; Status
C33731:  dw C3377E       ; /
C33733:  dw C33782       ; /
C33735:  dw C33795       ; /
C33737:  dw C33799       ; /
C33739:  dw C337AC       ; /
C3373B:  dw C337B0       ; /
C3373D:  dw C337C3       ; /
C3373F:  dw C337C7       ; /
C33741:  dw C3376F       ; LV
C33743:  dw C33774       ; HP
C33745:  dw C33779       ; MP
C33747:  dw C33786       ; LV
C33749:  dw C3378B       ; HP
C3374B:  dw C33790       ; MP
C3374D:  dw C3379D       ; LV
C3374F:  dw C337A2       ; HP
C33751:  dw C337A7       ; MP
C33753:  dw C337B4       ; LV
C33755:  dw C337B9       ; HP
C33757:  dw C337BE       ; MP
C33759:  dw C337DB       ; Equip
C3375B:  dw C337F4       ; Config
C3375D:  dw C3381C       ; Yes
C3375F:  dw C33822       ; No
C33761:  dw C33827       ; This
C33763:  dw C3382E       ; data?
C33765:  dw C3381C       ; Yes
C33767:  dw C33822       ; No
C33769:  dw C33836       ; Erasing
C3376B:  dw C33840       ; data.
C3376D:  dw C33848       ; Okay?

; Positioned text for main menu and save file submenus
C3376F:  dw $399D : db "LV",$00
C33774:  dw $39DD : db "HP",$00
C33779:  dw $3A1D : db "MP",$00
C3377E:  dw $39EB : db "/",$00
C33782:  dw $3A2B : db "/",$00
C33786:  dw $3B1D : db "LV",$00
C3378B:  dw $3B5D : db "HP",$00
C33790:  dw $3B9D : db "MP",$00
C33795:  dw $3B6B : db "/",$00
C33799:  dw $3BAB : db "/",$00
C3379D:  dw $3C9D : db "LV",$00
C337A2:  dw $3CDD : db "HP",$00
C337A7:  dw $3D1D : db "MP",$00
C337AC:  dw $3CEB : db "/",$00
C337B0:  dw $3D2B : db "/",$00
C337B4:  dw $3E1D : db "LV",$00
C337B9:  dw $3E5D : db "HP",$00
C337BE:  dw $3E9D : db "MP",$00
C337C3:  dw $3E6B : db "/",$00
C337C7:  dw $3EAB : db "/",$00
C337CB:  dw $7939 : db "Item",$00
C337D2:  dw $79B9 : db "Skills",$00
C337DB:  dw $7A39 : db "Equip",$00
C337E3:  dw $7AB9 : db "Relic",$00
C337EB:  dw $7B39 : db "Status",$00
C337F4:  dw $7BB9 : db "Config",$00
C337FD:  dw $7C39 : db "Save",$00
C33804:  dw $7CBB : db "Time",$00
C3380B:  dw $7CFF : db ":",$00
C3380F:  dw $7DB7 : db "Steps",$00
C33817:  dw $7E77 : db "Gp",$00
C3381C:  dw $7ABD : db "Yes",$00
C33822:  dw $7B3D : db "No",$00
C33827:  dw $7937 : db "This",$00
C3382E:  dw $79B7 : db "data?",$00
C33836:  dw $7937 : db "Erasing",$00
C33840:  dw $79B7 : db "data.",$00
C33848:  dw $7A37 : db "Okay?",$00
C33850:  dw $813D : db "Order",$00

; Load navigation data for Config page 1
C33858:  LDY #C33867     ; C3/3867
         JMP C305FE      ; Load navig data

; Handle D-Pad for Config page 1
C3385E:  JSR C3072D      ; Handle D-Pad
C33861:  LDY #C3386C     ; C3/386C
         JMP C30640      ; Relocate cursor

; Navigation data for Config page 1
C33867:  db $81          ; Never wraps
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $09          ; 9 rows

; Cursor positions for Config page 1
C3386C:  dw $2960        ; Bat.Mode
         dw $3960        ; Bat.Speed
         dw $4960        ; Msg.Speed
         dw $5960        ; Cmd.Set
         dw $6960        ; Gauge
         dw $7960        ; Sound
         dw $8960        ; Cursor
         dw $9960        ; Reequip
         dw $A960        ; Controller

; Load navigation data for Config page 2
C3387E:  LDY #C3388D     ; C3/388D
         JMP C305FE      ; Load navig data

; Handle D-Pad for Config page 2
C33884:  JSR C3072D      ; Handle D-Pad
C33887:  LDY #C33892     ; C3/3892
         JMP C30640      ; Relocate cursor

; Navigation data for Config page 2
C3388D:  db $81          ; Never wraps
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $06          ; 6 rows

; Cursor positions for Config page 2
C33892:  dw $2960        ; Mag.Order
         dw $6960        ; Window
         dw $7960        ; Color
         dw $9960        ; R
         dw $A960        ; G
         dw $B960        ; B

; Draw Config menu, load navigation data, create arrow
C3389E:  LDA #$02        ; 32x64 at $0000
         STA $2107       ; Set BG1 map loc
         LDY #$FFFB      ; Y: -5
         STY $3F         ; Set BG3 Y-Pos
         JSR C36A28      ; Clear BG2 map A
         LDY #C339E2     ; C3/39E2
         JSR C30341      ; Draw main window
         LDY #C339E6     ; C3/39E6
         JSR C30341      ; Draw title window
         JSR C30E52      ; Upload windows
         JSR C3395E      ; Load gauge colors
         JSR C36A15      ; Clear BG1 map A
         JSR C36A19      ; Clear BG1 map B
         JSR C36A3C      ; Clear BG3 map A
         JSR C36A41      ; Clear BG3 map B
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         LDY #C349A1     ; Text pointer
         JSR C302F9      ; Draw "Config"
         LDA #$24        ; Palette 1
         STA $29         ; Color: Blue
         LDX #C34993     ; Text ptrs loc
         LDY #$000E      ; Strings: 7
         JSR C369BA      ; Draw Bat.Mode, etc.
         LDA #$24        ; ...
         STA $29         ; ...
         LDX #C34903     ; Text ptrs loc
         LDY #$0004      ; Strings: 2
         JSR C369BA      ; Draw Cursor, Contr.
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDX #C34907     ; Text ptrs loc
         LDY #$0004      ; Strings: 2
         JSR C369BA      ; Draw Fast, Slow
         JSR C33B8C      ; Draw Active, Wait
         JSR C33BB7      ; Draw Bat.Spd nums
         JSR C33BF2      ; Draw Msg.Spd nums
         JSR C33C33      ; Draw Window, Short
         JSR C33C5C      ; Draw On and Off
         JSR C33C85      ; Draw Stereo, Mono
         JSR C33CB0      ; Draw Reset, Memory
         JSR C33CDB      ; Draw Optimum, Empty
         JSR C33D06      ; Draw Single/Multiple
         LDA #$24        ; Palette 1
         STA $29         ; Color: Blue
         LDX #C34A1C     ; Text ptrs loc
         LDY #$0006      ; Strings: 3
         JSR C369BA      ; Draw page-2 titles
         JSR C33950      ; Draw empty gauges
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDX #C34A28     ; Text ptrs loc
         LDY #$000C      ; Strings: 6
         JSR C369BA      ; Draw A/B/C, R/G/B
         JSR C33FFD      ; Draw M.Order options
         JSR C340EA      ; Draw skin numbers
         JSR C34133      ; Draw skin palette
         JSR C341C3      ; Draw RGB info
         JSR C339F5      ; Get nav data; BG1 Y
         JSR C30E28      ; Upload BG1 A+B
         JSR C30E6E      ; Upload BG3 A+B
         LDA #$01        ; Min slot: 8
         LDY #C33980     ; C3/3980
         JSR C31173      ; Queue arrow OAM
         RTS

; Draw empty color gauges
C33950:  LDA #$30        ; Palette 4
         STA $29         ; Color: Gray
         LDX #C34A22     ; Text ptrs loc
         LDY #$0006      ; Strings: 3
         JSR C369BA      ; Draw text
         RTS

; Load color gauge palette
C3395E:  LDX $00         ; Color index: 0
         LDA #$40        ; CGRAM: $0080
         STA $2121       ; To BG pal 4
C33965:  REP #$20        ; 16-bit A
         LDA $D8E880,X   ; Font color
         STA $7E30C9,X   ; Save in RAM
         SEP #$20        ; 8-bit A
         STA $2122       ; Put LB in CGRAM
         XBA             ; Switch to HB
         STA $2122       ; Put HB in CGRAM
         INX             ; Color index +1
         INX             ; Color index +1
         CPX #$0020      ; Done 16 colors?
         BNE C33965      ; Loop if not
         RTS

; Update arrow in Config menu
C33980:  TAX             ; Index mode
         JMP (C33984,X)  ; Handle mode

; Jump table for the above
C33984:  dw C33988       ; Initialize arrow
         dw C339AB       ; Sustain arrow

; Mode 0: Initialize arrow
C33988:  LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         LDA #C339CB     ; Anim table ptr
         STA $32C9,X     ; Set arrow's
         LDA #$0078      ; X: 120
         STA $33CA,X     ; Set arrow's
         LDA #$0018      ; Base Y: 24
         STA $344A,X     ; Set arrow's
         SEP #$20        ; 8-bit A
         LDA #$C3        ; Bank: C3
         STA $35CA,X     ; Set ptr HB
         INC $3649,X     ; Mode +1
         JSR C31206      ; Set pose timer

; Mode 1: Sustain arrow
C339AB:  LDY $2D         ; Queue index
         LDA $4A         ; On first page?
         BEQ C339B5      ; Branch if so
         LDA #$02        ; Arrow: Up
         BRA C339B6      ; Skip a line
C339B5:  TDC             ; Arrow: Down
C339B6:  TAX             ; Set index
         REP #$20        ; 16-bit A
         LDA.L C339C7,X  ; Anim table ptr
         STA $32C9,Y     ; Set arrow's
         SEP #$20        ; ...
         JSR C31221      ; Define OAM
         SEC             ; Set to requeue
         RTS

; Pointers for Config's large arrows
C339C7:  dw C339CB       ; Downward arrow
         dw C339D4       ; Upward arrow

; Animation table for large downward arrow
C339CB:  dw C3B45B       ; Hide arrow
         db $10          ; Frames: 16
         dw C339DD       ; Show arrow
         db $10          ; Frames: 16
         dw C3B45B       ; Bogus...
         db $FF          ; Loop

; Animation table for large upward arrow
C339D4:  dw C3B45B       ; Hide arrow
         db $10          ; Frames: 16
         dw C3B461       ; Show arrow
         db $10          ; Frames: 16
         dw C3B45B       ; Bogus...
         db $FF          ; Loop

; OAM for large downward arrow
C339DD:  db $01          ; Tiles: 1
         dw $B080        ; 16x16, X+0, Y+176
         dw $3E03        ; Tile 3, pal 7, prio 3

; Window layout for Config menu
C339E2:  dw $590B,$161C  ; 30x24 at $590B (Main)
C339E6:  dw $58B7,$0206  ; 08x04 at $58B7 (Title)

; Switch to Config page 2
C339EA:  LDY #$00FB      ; Y: 251
         STY $37         ; Set BG1 Y-Pos
         JSR C3387E      ; Load navig data
         JMP C33887      ; Relocate cursor

; Switch to Config page 1
C339F5:  LDY #$FFFB      ; Y: -5
         STY $37         ; Set BG1 Y-Pos
         JSR C33858      ; Load navig data
         JMP C33861      ; Relocate cursor

; 50: Scroll to Config page 2
C33A00:  LDA $20         ; Timer expired?
         BEQ C33A15      ; Finalize if so
         LDA $4A         ; On page 2?...
         BNE C33A1C      ; Branch if so
         REP #$20        ; 16-bit A
         LDA $37         ; BG1 Y-Pos
         CLC             ; Prepare ADC
         ADC #$0010      ; Move 16 px down
         STA $37         ; Save changes
         SEP #$20        ; 8-bit A
         RTS             ; Exit
C33A15:  LDA #$01        ; Screen: 2nd
         STA $4A         ; Set active page
         JSR C339EA      ; Switch screens
C33A1C:  LDA #$0E        ; C3/22C5
         STA $26         ; Next: Sustain menu
         RTS

; 51: Scroll to Config page 1
C33A21:  LDA $20         ; Timer expired?
         BEQ C33A36      ; Finalize if so
         LDA $4A         ; On page 1?...
         BEQ C33A47      ; Branch if so
         REP #$20        ; 16-bit A
         LDA $37         ; BG1 Y-Pos
         SEC             ; Prepare SBC
         SBC #$0010      ; Move 16 px up
         STA $37         ; Save changes
         SEP #$20        ; 8-bit A
         RTS             ; Exit
C33A36:  STZ $4A         ; Page: 1st
         LDY #$FFFB      ; Y: -5
         STY $37         ; Set BG1 Y-Pos
         JSR C33858      ; Load navig data
         LDA #$08        ; Row: Controller
         STA $4E         ; Set cursor row
         JSR C33861      ; Relocate cursor
C33A47:  LDA #$0E        ; C3/22C5
         STA $26         ; Next: Sustain menu
         RTS

; Set Window 2 positions per scanline for Config menu
C33A4C:  LDA #$01        ; 2Rx1B to PPU
         STA $4350       ; Set DMA mode
         LDA #$28        ; $2128, $2129
         STA $4351       ; To Win 2 L+R
         LDY #C33A7A     ; C3/3A7A
         STY $4352       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4354       ; Set src HB
         LDA #$C3        ; ...
         STA $4357       ; Set indir HB
         LDA #$20        ; Channel: 5
         TSB $43         ; Queue HDMA-5
         RTS

; Set Window 2 positions for main menu
C33A6B:  LDA #$20        ; Channel: 5
         TRB $43         ; Halt HDMA-5
         LDA #$08        ; X: 8
         STA $2128       ; Set left loc
         LDA #$F7        ; X: 247
         STA $2129       ; Set right loc
         RTS

; Window 2 positions per scanline for Config menu
C33A7A:  db $27,$FF,$FF  ; 39 lines: 255, 255
         db $50,$08,$F7  ; 80 lines: 8, 247
         db $50,$08,$F7  ; 80 lines: 8, 247
         db $10,$FF,$FF  ; 16 lines: 255, 255
         db $00          ; End

; Upload skin graphics, load colors and tile attributes
C33A87:  LDY #$7800      ; $F000
         STY $14         ; Set VRAM ptr
         LDA $1D4E       ; Skin, etc.
         JSR C33B30      ; Set source
         LDA $1D4E       ; Skin, etc.
         LDX #$0060      ; To 7E/312B
         JSR C33B5B      ; Load colors
         LDY #$1C00      ; Palette: 7
         JMP C30326      ; Build skin map

; Upload skin for save file 1
C33AA1:  LDY #$7A00      ; $F400
         STY $14         ; Set VRAM ptr
         LDY $91         ; Blank file?
         BEQ C33AB0      ; Branch if so
         LDA $30674E     ; Skin, etc.
         BRA C33AB1      ; Skip a line
C33AB0:  TDC             ; Use skin 1
C33AB1:  JSR C33B30      ; Set source
         JSR C31488      ; Upload skin
         LDY #$1820      ; Tile+32, pal 6
         JMP C30326      ; Build skin map

; Upload skin for save file 2
C33ABD:  LDY #$7C00      ; $F800
         STY $14         ; Set VRAM ptr
         LDY $93         ; Blank file?
         BEQ C33ACC      ; Branch if so
         LDA $30714E     ; Skin, etc.
         BRA C33ACD      ; Skip a line
C33ACC:  TDC             ; Use skin 1
C33ACD:  JSR C33B30      ; Set source
         JSR C31488      ; Upload skin
         LDY #$1440      ; Tile+64, pal 5
         JMP C30326      ; Build skin map

; Upload skin for save file 3
C33AD9:  LDY #$7E00      ; $FC00
         STY $14         ; Set VRAM ptr
         LDY $95         ; Blank file?
         BEQ C33AE8      ; Branch if so
         LDA $307B4E     ; Skin, etc.
         BRA C33AE9      ; Skip a line
C33AE8:  TDC             ; Use skin 1
C33AE9:  JSR C33B30      ; Set source
         JSR C31488      ; Upload skin
         LDY #$1060      ; Tile+96, pal 4
         JMP C30326      ; Build skin map

; Load skin colors for save file 1
C33AF5:  LDY $91         ; Blank file?
         BEQ C33AFF      ; Branch if so
         LDA $30674E     ; Skin, etc.
         BRA C33B00      ; Skip a line
C33AFF:  TDC             ; Use skin 1
C33B00:  LDX #$0040      ; To 7E/310B
         JSR C33B5B      ; Load colors
         JMP C314D2      ; Refresh CGRAM

; Load skin colors for save file 2
C33B09:  LDY $93         ; Blank file?
         BEQ C33B13      ; Branch if so
         LDA $30714E     ; Skin, etc.
         BRA C33B14      ; Skip a line
C33B13:  TDC             ; Use skin 1
C33B14:  LDX #$0020      ; To 7E/30EB
         JSR C33B5B      ; Load colors
         JMP C314D2      ; Refresh CGRAM

; Load skin colors for save file 3
C33B1D:  LDY $95         ; Blank file?
         BEQ C33B27      ; Branch if so
         LDA $307B4E     ; Skin, etc.
         BRA C33B28      ; Skip a line
C33B27:  TDC             ; Use skin 1
C33B28:  LDX $00         ; To 7E/30CB
         JSR C33B5B      ; Load colors
         JMP C314D2      ; Refresh CGRAM

; Set source for uploading skin graphics
C33B30:  AND #$0F        ; Skin number
         STA $E0         ; Set counter
         STZ $E1         ; Clear HB
         LDY #$0000      ; ED/0000
         STY $16         ; Set src LBs
         LDA #$ED        ; Bank: ED
         STA $18         ; Set src HB
         REP #$20        ; 16-bit A
         TDC             ; Source mod: 0
C33B42:  LDY $E0         ; Loop counter
         BEQ C33B4E      ; Branch if 0
         CLC             ; Prepare ADC
         ADC #$0380      ; Adjust src mod
         DEC $E0         ; Counter -1
         BRA C33B42      ; Loop
C33B4E:  CLC             ; Prepare ADC
         ADC $16         ; Add src LBs
         STA $16         ; Set src LBs
         SEP #$20        ; 8-bit A
         LDY #$0400      ; Bytes: 1024
         STY $12         ; Set data size
         RTS

; Apply player's skin colors
C33B5B:  AND #$0F        ; Skin number
         STA $E0         ; Set counter
         PHX             ; ...
         LDA #$00        ; Bank: 00
         STA $E9         ; Set src HB
         STZ $E1         ; Counter HB: 0
         REP #$20        ; 16-bit A
         LDA #$1D57      ; Base: 7E/1D57
C33B6B:  LDY $E0         ; Loop counter
         BEQ C33B77      ; Branch if 0
         CLC             ; Prepare ADC
         ADC #$000E      ; Skip 7 colors
         DEC $E0         ; Counter -1
         BRA C33B6B      ; Loop
C33B77:  STA $E7         ; Set source LBs
         SEP #$20        ; 8-bit A
         LDY $00         ; Src index: 0
         PLX             ; ...
C33B7E:  LDA [$E7],Y     ; Player color
         STA $7E30CB,X   ; Put in palette
         INY             ; Src index +1
         INX             ; Dst index +1
         CPY #$000E      ; Done 7 colors?
         BNE C33B7E      ; Loop if not
         RTS

; Draw Bat.Mode settings
C33B8C:  LDA $1D4D       ; Game options
         AND #$08        ; Wait mode?
         BEQ C33B9C      ; Branch if not
         LDA #$28        ; Color: Gray
         JSR C33BA5      ; Draw "Active"
         LDA #$20        ; Color: User's
         BRA C33BAE      ; Draw "Wait"

; Fork: Active mode
C33B9C:  LDA #$20        ; Color: User's
         JSR C33BA5      ; Draw "Active"
         LDA #$28        ; Color: Gray
         BRA C33BAE      ; Draw "Wait"

; Fork: Draw "Active"
C33BA5:  STA $29         ; Set palette
         LDY #C349F1     ; Text pointer
         JSR C302F9      ; Draw "Active"
         RTS

; Fork: Draw "Wait"
C33BAE:  STA $29         ; Set palette
         LDY #C34918     ; Text pointer
         JSR C302F9      ; Draw "Wait"
         RTS

; Draw Bat.Speed values
C33BB7:  LDA #$28        ; Palette 2
         STA $29         ; Color: Gray
         LDY #C3496E     ; Text pointer
         JSR C302F9      ; Draw 1-6 in gray
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         TDC             ; Clear A
         LDA $1D4D       ; Game options
         AND #$07        ; Get Bat.Speed
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C33BE6,X  ; Tilemap ptr
         STA $F7         ; Set position
         SEP #$20        ; 8-bit A
         LDA $1D4D       ; Game options
         AND #$07        ; Get Bat.Speed
         CLC             ; ...
         ADC.B #!num1    ; Convert to text
         STA $F9         ; Add to string
         STZ $FA         ; End string
         JMP C34116      ; Draw user speed

; Tilemap pointers for Bat.Speed values
C33BE6:  dw $3A25        ; 1
         dw $3A29        ; 2
         dw $3A2D        ; 3
         dw $3A31        ; 4
         dw $3A35        ; 5
         dw $3A39        ; 6

; Draw Msg.Speed values
C33BF2:  LDA #$28        ; Palette 2
         STA $29         ; Color: Gray
         LDY #C3497C     ; Text pointer
         JSR C302F9      ; Draw 1-6 in gray
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         TDC             ; Clear A
         LDA $1D4D       ; Game options
         AND #$70        ; Get Msg.Speed
         LSR A           ; ÷2
         LSR A           ; ÷4
         LSR A           ; ÷8
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C33C27,X  ; Tilemap ptr
         STA $F7         ; Set position
         SEP #$20        ; 8-bit A
         LDA $1D4D       ; Game options
         AND #$70        ; Get Msg.Speed
         LSR A           ; ÷2
         LSR A           ; ÷4
         LSR A           ; ÷8
         LSR A           ; Now 0-7
         CLC             ; ...
         ADC.B #!num1    ; Convert to text
         STA $F9         ; Add to string
         STZ $FA         ; End string
         JMP C34116      ; Draw user speed

; Tilemap pointers for Msg.Speed values
C33C27:  dw $3AA5        ; 1
         dw $3AA9        ; 2
         dw $3AAD        ; 3
         dw $3AB1        ; 4
         dw $3AB5        ; 5
         dw $3AB9        ; 6

; Draw Cmd.Set settings
C33C33:  LDA $1D4D       ; Short mode?
         BMI C33C41      ; Branch if so
         LDA #$28        ; Color: Gray
         JSR C33C4A      ; Draw "Short"
         LDA #$20        ; Color: User's
         BRA C33C53      ; Draw "Window"

; Fork: Short mode
C33C41:  LDA #$20        ; Color: User's
         JSR C33C4A      ; Draw "Short"
         LDA #$28        ; Color: Gray
         BRA C33C53      ; Draw "Window"

; Fork: Draw "Short"
C33C4A:  STA $29         ; Set palette
         LDY #C3492D     ; Text pointer
         JSR C302F9      ; Draw "Short"
         RTS

; Fork: Draw "Window"
C33C53:  STA $29         ; Set palette
         LDY #C349FA     ; Text pointer
         JSR C302F9      ; Draw "Window"
         RTS

; Draw Gauge settings
C33C5C:  LDA $1D4E       ; Gauges on?
         BPL C33C6A      ; Branch if so
         LDA #$28        ; Color: Gray
         JSR C33C73      ; Draw "On"
         LDA #$20        ; Color: User's
         BRA C33C7C      ; Draw "Off"

; Fork: Gauges on
C33C6A:  LDA #$20        ; Color: User's
         JSR C33C73      ; Draw "On"
         LDA #$28        ; Color: Gray
         BRA C33C7C      ; Draw "Off"

; Fork: Draw "On"
C33C73:  STA $29         ; Set palette
         LDY #C34935     ; Text pointer
         JSR C302F9      ; Draw "On"
         RTS

; Fork: Draw "Off"
C33C7C:  STA $29         ; Set palette
         LDY #C3493A     ; Text pointer
         JSR C302F9      ; Draw "Off"
         RTS

; Draw Sound settings
C33C85:  LDA $1D4E       ; Game options
         AND #$20        ; Stereo?
         BEQ C33C95      ; Branch if so
         LDA #$28        ; Color: Gray
         JSR C33C9E      ; Draw "Stereo"
         LDA #$20        ; Color: User's
         BRA C33CA7      ; Draw "Mono"

; Fork: Stereo mode
C33C95:  LDA #$20        ; Color: User's
         JSR C33C9E      ; Draw "Stereo"
         LDA #$28        ; Color: Gray
         BRA C33CA7      ; Draw "Mono"

; Fork: Draw "Stereo"
C33C9E:  STA $29         ; Set palette
         LDY #C34940     ; Text pointer
         JSR C302F9      ; Draw "Stereo"
         RTS

; Fork: Draw "Mono"
C33CA7:  STA $29         ; Set palette
         LDY #C34949     ; Text pointer
         JSR C302F9      ; Draw "Mono"
         RTS

; Draw Cursor settings
C33CB0:  LDA $1D4E       ; Game options
         AND #$40        ; Cursor memory?
         BEQ C33CC0      ; Branch if not
         LDA #$28        ; Color: Gray
         JSR C33CC9      ; Draw "Reset"
         LDA #$20        ; Color: User's
         BRA C33CD2      ; Draw "Memory"

; Fork: Reset mode
C33CC0:  LDA #$20        ; Color: User's
         JSR C33CC9      ; Draw "Reset"
         LDA #$28        ; Color: Gray
         BRA C33CD2      ; Draw "Memory"

; Fork: Draw "Reset"
C33CC9:  STA $29         ; Set palette
         LDY #C34A03     ; Text pointer
         JSR C302F9      ; Draw "Reset"
         RTS

; Fork: Draw "Memory"
C33CD2:  STA $29         ; Set palette
         LDY #C34950     ; Text pointer
         JSR C302F9      ; Draw "Memory"
         RTS

; Draw Reequip settings
C33CDB:  LDA $1D4E       ; Game options
         AND #$10        ; Optimum mode?
         BEQ C33CEB      ; Branch if so
         LDA #$28        ; Color: Gray
         JSR C33CF4      ; Draw "Optimum"
         LDA #$20        ; Color: User's
         BRA C33CFD      ; Draw "Empty"

; Fork: Optimum mode
C33CEB:  LDA #$20        ; Color: User's
         JSR C33CF4      ; Draw "Optimum"
         LDA #$28        ; Color: Gray
         BRA C33CFD      ; Draw "Empty"

; Fork: Draw "Optimum"
C33CF4:  STA $29         ; Set palette
         LDY #C34959     ; Text pointer
         JSR C302F9      ; Draw "Optimum"
         RTS

; Fork: Draw "Empty"
C33CFD:  STA $29         ; Set palette
         LDY #C34A0B     ; Text pointer
         JSR C302F9      ; Draw "Empty"
         RTS

; Draw Controller settings
C33D06:  LDA $1D54       ; Solo mode?
         BPL C33D14      ; Branch if so
         LDA #$28        ; Color: Gray
         JSR C33D1D      ; Draw "Single"
         LDA #$20        ; Color: User's
         BRA C33D26      ; Draw "Multiple"

; Fork: Single mode
C33D14:  LDA #$20        ; Color: User's
         JSR C33D1D      ; Draw "Single"
         LDA #$28        ; Color: Gray
         BRA C33D26      ; Draw "Multiple"

; Fork: Draw "Single"
C33D1D:  STA $29         ; Set palette
         LDY #C34A13     ; Text pointer
         JSR C302F9      ; Draw "Single"
         RTS

; Fork: Draw "Multiple"
C33D26:  STA $29         ; Set palette
         LDY #C34963     ; Text pointer
         JSR C302F9      ; Draw "Multiple"
         RTS

; Handle Config changes with D-Pad
C33D2F:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA $4A         ; On first page?
         BEQ C33D40      ; Branch if so
         PHX             ; ...
         JSR C30EA3      ; Sound: Cursor
         PLX             ; ...
         JMP (C33D55,X)  ; Handle page 2
C33D40:  JMP (C33D43,X)  ; Handle page 1

; Jump table for updating game options
C33D43:  dw C33D61       ; Bat.Mode
         dw C33D7A       ; Bat.Speed
         dw C33DAB       ; Msg.Speed
         dw C33DE8       ; Cmd.Set
         dw C33E01       ; Gauge
         dw C33E1A       ; Sound
         dw C33E4E       ; Cursor
         dw C33E6D       ; Reequip
         dw C33E86       ; Controller
C33D55:  dw C33E9F       ; Mag.Order
         dw C33ECD       ; Window
         dw C33F01       ; Viewed color
         dw C33F3C       ; R
         dw C33F5B       ; G
         dw C33F7A       ; B

; Update Bat.Mode
C33D61:  JSR C30EA3      ; Sound: Cursor
         LDA $0B         ; Semi-auto keys
         BIT #$01        ; Pushing right?
         BNE C33D72      ; Branch if so
         LDA #$08        ; Mode: Active
         TRB $1D4D       ; Set option
         JMP C33B8C      ; Redraw text
C33D72:  LDA #$08        ; Mode: Wait
         TSB $1D4D       ; Set option
         JMP C33B8C      ; Redraw text

; Update Bat.Speed
C33D7A:  JSR C30EA3      ; Sound: Cursor
         LDA $1D4D       ; Game options
         AND #$07        ; Get Bat.Speed
         STA $E0         ; Memorize it
         LDA $0B         ; Semi-auto keys
         BIT #$01        ; Pushing right?
         BEQ C33D95      ; Branch if not

; Fork: Bat.Speed +1
C33D8A:  LDA $E0         ; Bat.Speed
         CMP #$05        ; Rightmost?
         BEQ C33D94      ; Exit if so
         INC $E0         ; Speed +1
         BRA C33D9E      ; Apply changes
C33D94:  RTS

; Fork: Bat.Speed -1
C33D95:  LDA $E0         ; Leftmost speed?
         BEQ C33D9D      ; Exit if so
         DEC $E0         ; Speed -1
         BRA C33D9E      ; Apply changes
C33D9D:  RTS

; Fork: Apply Bat.Speed
C33D9E:  LDA $1D4D       ; Game options
         AND #$F8        ; Clear Bat.Speed
         ORA $E0         ; Set chosen speed
         STA $1D4D       ; Save changes
         JMP C33BB7      ; Redraw values

; Update Msg.Speed
C33DAB:  JSR C30EA3      ; Sound: Cursor
         LDA $1D4D       ; Game options
         AND #$70        ; Get Msg.Speed
         LSR A           ; Put in b3-b5
         LSR A           ; Put in b2-b4
         LSR A           ; Put in b1-b3
         LSR A           ; Now 0-5
         STA $E0         ; Memorize it
         LDA $0B         ; Semi-auto keys
         BIT #$01        ; Pushing right?
         BEQ C33DCA      ; Branch if not

; Fork: Msg.Speed +1
C33DBF:  LDA $E0         ; Msg.Speed
         CMP #$05        ; Rightmost?
         BEQ C33DC9      ; Exit if so
         INC $E0         ; Speed +1
         BRA C33DD3      ; Apply changes
C33DC9:  RTS

; Fork: Msg.Speed -1
C33DCA:  LDA $E0         ; Leftmost speed?
         BEQ C33DD2      ; Exit if so
         DEC $E0         ; Speed -1
         BRA C33DD3      ; Apply changes
C33DD2:  RTS

; Fork: Apply Msg.Speed
C33DD3:  LDA $E0         ; Chosen speed
         ASL A           ; x2
         ASL A           ; x4
         ASL A           ; x8
         ASL A           ; x16
         STA $E0         ; Save changes
         LDA $1D4D       ; Game options
         AND #$8F        ; Clear Msg.Speed
         ORA $E0         ; Set chosen speed
         STA $1D4D       ; Save changes
         JMP C33BF2      ; Redraw values

; Update Cmd.Set mode
C33DE8:  JSR C30EA3      ; Sound: Cursor
         LDA $0B         ; Semi-auto keys
         BIT #$01        ; Pushing right?
         BNE C33DF9      ; Branch if so
         LDA #$80        ; Mode: Window
         TRB $1D4D       ; Set option
         JMP C33C33      ; Redraw options
C33DF9:  LDA #$80        ; Mode: Short
         TSB $1D4D       ; Set option
         JMP C33C33      ; Redraw options

; Update gauge mode
C33E01:  JSR C30EA3      ; Sound: Cursor
         LDA $0B         ; Semi-auto keys
         BIT #$01        ; Pushing right?
         BNE C33E12      ; Branch if so
         LDA #$80        ; Gauge: On
         TRB $1D4E       ; Set option
         JMP C33C5C      ; Redraw options
C33E12:  LDA #$80        ; Gauge: Off
         TSB $1D4E       ; Set option
         JMP C33C5C      ; Redraw options

; Update sound mode
C33E1A:  LDA $0B         ; Semi-auto keys
         BIT #$01        ; Pushing right?
         BNE C33E2F      ; Branch if so
         TDC             ; Volume: Stereo
         JSR C33E3F      ; Adjust volume
         LDA #$20        ; Mode: Stereo
         TRB $1D4E       ; Set option
         JSR C30EA3      ; Sound: Cursor
         JMP C33C85      ; Redraw options
C33E2F:  LDA #$FF        ; Volume: Mono
         JSR C33E3F      ; Adjust volume
         LDA #$20        ; Mono flag
         TSB $1D4E       ; Set mono mode
         JSR C30EA3      ; Sound: Cursor
         JMP C33C85      ; Redraw options

; Adjust volume based on sound mode (stereo = 0)
C33E3F:  STA $001301     ; Set sound mode
         LDA #$F3        ; SPC code: $0D61
         STA $001300     ; Set SPC command
         JSL $C50004     ; Update ports
         RTS

; Update Cursor mode
C33E4E:  JSR C30EA3      ; Sound: Cursor
         LDA $0B         ; Semi-auto keys
         BIT #$01        ; Pushing right?
         BNE C33E62      ; Branch if so
         JSR C348F7      ; Forget positions
         LDA #$40        ; Mode: Reset
         TRB $1D4E       ; Set option
         JMP C33CB0      ; Redraw options
C33E62:  LDA #$40        ; Mode: Memory
         TSB $1D4E       ; Set option
         JSR C37068      ; Reset positions
         JMP C33CB0      ; Redraw options

; Update Reequip mode
C33E6D:  JSR C30EA3      ; Sound: Cursor
         LDA $0B         ; Semi-auto keys
         BIT #$01        ; Pushing right?
         BNE C33E7E      ; Branch if so
         LDA #$10        ; Mode: Optimum
         TRB $1D4E       ; Set option
         JMP C33CDB      ; Redraw options
C33E7E:  LDA #$10        ; Mode: Empty
         TSB $1D4E       ; Set option
         JMP C33CDB      ; Redraw options

; Update Controller mode
C33E86:  JSR C30EA3      ; Sound: Cursor
         LDA $0B         ; Semi-auto keys
         BIT #$01        ; Pushing right?
         BNE C33E97      ; Branch if so
         LDA #$80        ; Mode: Single
         TRB $1D54       ; Set option
         JMP C33D06      ; Redraw options
C33E97:  LDA #$80        ; Mode: Multiple
         TSB $1D54       ; Set option
         JMP C33D06      ; Redraw options

; Update Mag.Order
C33E9F:  LDA $1D54       ; Game options
         AND #$07        ; Get Mag.Order
         STA $E0         ; Memorize it
         LDA $0B         ; Semi-auto keys
         BIT #$01        ; Pushing right?
         BEQ C33EB7      ; Branch if not

; Fork: Mag.Order +1
C33EAC:  LDA $E0         ; Mag.Order
         CMP #$05        ; Rightmost?
         BEQ C33EB6      ; Exit if so
         INC $E0         ; Order +1
         BRA C33EC0      ; Apply changes
C33EB6:  RTS

; Fork: Mag.Order -1
C33EB7:  LDA $E0         ; On "1" now?
         BEQ C33EBF      ; Exit if so
         DEC $E0         ; Order -1
         BRA C33EC0      ; Apply changes
C33EBF:  RTS

; Fork: Apply Mag.Order
C33EC0:  LDA $1D54       ; Game options
         AND #$F8        ; Clear Mag.Order
         ORA $E0         ; Set chosen one
         STA $1D54       ; Save changes
         JMP C33FFD      ; Redraw text

; Handle wallpaper selection
C33ECD:  LDA $1D4E       ; Game options
         AND #$0F        ; Get wallpaper
         STA $E0         ; Memorize it
         LDA $0B         ; Semi-auto keys
         BIT #$01        ; Pushing right?
         BEQ C33EE5      ; Branch if not

; Fork: Pushing right
C33EDA:  LDA $E0         ; Wallpaper
         CMP #$07        ; Rightmost?
         BEQ C33EE4      ; Exit if so
         INC $E0         ; Skin number +1
         BRA C33EEE      ; Apply changes
C33EE4:  RTS

; Fork: Pushing left
C33EE5:  LDA $E0         ; On "1" now?
         BEQ C33EED      ; Exit if so
         DEC $E0         ; Skin number -1
         BRA C33EEE      ; Apply changes
C33EED:  RTS

; Fork: Apply wallpaper
C33EEE:  LDA $1D4E       ; Game options
         AND #$F0        ; Clear skin
         ORA $E0         ; Set chosen one
         STA $1D4E       ; Save changes
         JSR C340EA      ; Redraw values
         JSR C33A87      ; Refresh skin
         JMP C341C3      ; Draw RGB info

; Change viewed color in Config
C33F01:  LDA $1D54       ; Game options
         AND #$38        ; Viewed color
         LSR A           ; Put in b2-b4
         LSR A           ; Put in b1-b3
         LSR A           ; Now 0-7
         STA $E0         ; Memorize it
         LDA $0B         ; Semi-auto keys
         BIT #$01        ; Pushing right?
         BEQ C33F1C      ; Branch if not

; Fork: Move to next color
C33F11:  LDA $E0         ; Viewed color
         CMP #$07        ; Rightmost?
         BEQ C33F1B      ; Exit if so
         INC $E0         ; Color number +1
         BRA C33F25      ; Apply changes
C33F1B:  RTS

; Fork: Move to preceding color
C33F1C:  LDA $E0         ; Editing font?
         BEQ C33F24      ; Exit if so
         DEC $E0         ; Color number -1
         BRA C33F25      ; Apply changes
C33F24:  RTS

; Fork: Apply selection
C33F25:  LDA $E0         ; Viewed color
         ASL A           ; Put in b1-b3
         ASL A           ; Put in b2-b4
         ASL A           ; Put in b3-b5
         STA $E0         ; Save changes
         LDA $1D54       ; Game options
         AND #$C7        ; Clear vwd color
         ORA $E0         ; Set new one
         STA $1D54       ; Save changes
         JSR C34133      ; Redraw arrow
         JMP C341C3      ; Draw RGB info

; Update red component of font or skin color
C33F3C:  JSR C341FE      ; Separate RGB
         LDA $0B         ; Semi-auto keys
         BIT #$01        ; Pushing right?
         BEQ C33F4F      ; Branch if not
         LDA $E2         ; Red
         CMP #$1F        ; 31?
         BEQ C33F55      ; Branch if so
         INC $E2         ; Red +1
         BRA C33F55      ; Apply changes
C33F4F:  LDA $E2         ; Red
         BEQ C33F55      ; Branch if 0
         DEC $E2         ; Red -1
C33F55:  JSR C34221      ; Merge RGB
         JMP C33FC4      ; Apply changes

; Update green component of font or skin color
C33F5B:  JSR C341FE      ; Separate RGB
         LDA $0B         ; Semi-auto keys
         BIT #$01        ; Pushing right?
         BEQ C33F6E      ; Branch if not
         LDA $E1         ; Green
         CMP #$1F        ; 31?
         BEQ C33F74      ; Branch if so
         INC $E1         ; Green +1
         BRA C33F74      ; Apply changes
C33F6E:  LDA $E1         ; Green
         BEQ C33F74      ; Branch if 0
         DEC $E1         ; Green -1
C33F74:  JSR C34221      ; Merge RGB
         JMP C33FC4      ; Apply changes

; Update blue component of font or skin color
C33F7A:  JSR C341FE      ; Separate RGB
         LDA $0B         ; Semi-auto keys
         BIT #$01        ; Pushing right?
         BEQ C33F8D      ; Branch if not
         LDA $E0         ; Blue
         CMP #$1F        ; 31?
         BEQ C33F93      ; Branch if so
         INC $E0         ; Blue +1
         BRA C33F93      ; Apply changes
C33F8D:  LDA $E0         ; Blue
         BEQ C33F93      ; Branch if 0
         DEC $E0         ; Blue -1
C33F93:  JSR C34221      ; Merge RGB
         JMP C33FC4      ; Apply changes

; Apply player's font color
C33F99:  REP #$20        ; 16-bit A
         LDA $1D55       ; User font color
         STA $7E304F     ; Set for FWF
         STA $7E3073     ; Set VWF color A
         STA $7E3077     ; Set VWF color B
         SEP #$20        ; 8-bit A
         RTS

; Apply player's skin colors after changes
C33FAD:  LDX $00         ; Dst index: 0
         REP #$20        ; 16-bit A
C33FB1:  LDA $1D57,Y     ; Player color
         STA $7E312B,X   ; Put in palette
         INY             ; Src index +1
         INY             ; Src index +1
         INX             ; Dst index +1
         INX             ; Dst index +1
         CPX #$000E      ; Done 7 colors?
         BNE C33FB1      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Apply player's skin or font colors after changes
C33FC4:  TDC             ; Clear A
         LDA $1D4E       ; Game options
         AND #$0F        ; Get wallpaper
         STA $4202       ; Set multiplicand
         LDA #$0E        ; Palette size
         STA $4203       ; Set multiplier
         LDA $1D54       ; Game options
         AND #$38        ; Viewed color
         BEQ C33FF2      ; Branch if font
         LSR A           ; Put in b2-b4
         LSR A           ; Put in b1-b3
         CLC             ; Prepare ADC
         ADC $4216       ; Add product
         TAX             ; Index sum
         LDA $9A         ; New color LB
         STA $1D55,X     ; Set as user's
         LDA $9B         ; New color HB
         STA $1D56,X     ; Set as user's
         LDY $4216       ; Palette index
         JSR C33FAD      ; Recolor skin
         BRA C33FFA      ; Redraw RGB info

; Fork: Font
C33FF2:  LDY $9A         ; Updated color
         STY $1D55       ; Put in options
         JSR C33F99      ; Put in palettes
C33FFA:  JMP C341C3      ; Redraw RGB info

; Draw Mag.Order settings
C33FFD:  LDA #$28        ; Palette 2
         STA $29         ; Color: Gray
         LDY #C34AA5     ; Text pointer
         JSR C302F9      ; Draw 1-6 in gray
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         TDC             ; Clear A
         LDA $1D54       ; Game options
         AND #$07        ; Get Mag.Order
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C3402F,X  ; Tilemap ptr
         STA $F7         ; Set position
         SEP #$20        ; 8-bit A
         LDA $1D54       ; Game options
         AND #$07        ; Get Mag.Order
         CLC             ; ...
         ADC.B #!num1    ; Convert to text
         STA $F9         ; Add to string
         STZ $FA         ; End string
         JSR C34116      ; Draw user value
         JMP C3403B      ; Draw spell types

; Tilemap pointers for Mag.Order values
C3402F:  dw $41A5        ; 1
         dw $41A9        ; 2
         dw $41AD        ; 3
         dw $41B1        ; 4
         dw $41B5        ; 5
         dw $41B9        ; 6

; Draw all three Mag.Order spell types
C3403B:  TDC             ; Clear A
         STA $7E9E95     ; Set string end
         TDC             ; ...
         LDA $1D54       ; Game options
         AND #$07        ; Get Mag.Order
         ASL A           ; x2
         ASL A           ; x4
         TAX             ; Index it
         LDY #$0003      ; Strings: 3
C3404C:  PHY             ; Save counter
         PHX             ; Save index
         JSR C34058      ; Draw string
         PLX             ; String index
         PLY             ; Strings left
         INX             ; Point to next
         DEY             ; One less left
         BNE C3404C      ; Loop till last
         RTS

; Draw current Mag.Order spell type
C34058:  TDC             ; Clear A
         LDA.L C340D2,X  ; Text pointer
         TAX             ; Index it
         LDA.L C34AD3,X  ; Spell icon
         STA $7E9E8B     ; To string
         LDA.L C34AD3+1,X; Letter 1
         STA $7E9E8C     ; To string
         LDA.L C34AD3+2,X; Letter 2
         STA $7E9E8D     ; To string
         LDA.L C34AD3+3,X; Letter 3
         STA $7E9E8E     ; To string
         LDA.L C34AD3+4,X; Letter 4
         STA $7E9E8F     ; To string
         LDA.L C34AD3+5,X; Letter 5
         STA $7E9E90     ; To string
         LDA.L C34AD3+6,X; Letter 6
         STA $7E9E91     ; To string
         LDA.L C34AD3+7,X; Letter 7
         STA $7E9E92     ; To string
         LDA.L C34AD3+8,X; Letter 8
         STA $7E9E93     ; To string
         LDA.L C34AD3+9,X; Letter 9
         STA $7E9E94     ; To string
         TDC             ; ...
         DEY             ; Lines left -1
         TYA             ; Put it in A
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C340CC,X  ; Tilemap ptr
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         LDY #$9E89      ; 7E/9E89
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         JSR C302FF      ; Draw string
         RTS

; Tilemap pointers for Mag.Order strings
C340CC:  dw $4329        ; Spell type C
         dw $42A9        ; Spell type B
         dw $4229        ; Spell type A

; Relative pointers to Mag.Order strings
C340D2:  db $00,$0A,$14  ; Healing, Attack, Effect
         db $00          ; ...
         db $00,$14,$0A  ; Healing, Effect, Attack
         db $00          ; ...
         db $0A,$14,$00  ; Attack, Effect, Healing
         db $00          ; ...
         db $0A,$00,$14  ; Attack, Healing, Effect
         db $00          ; ...
         db $14,$00,$0A  ; Effect, Healing, Attack
         db $00          ; ...
         db $14,$0A,$00  ; Effect, Attack, Healing
         db $00          ; ...

; Draw wallpaper values
C340EA:  LDA #$28        ; Palette 2
         STA $29         ; Color: Gray
         LDY #C34A93     ; Text pointer
         JSR C302F9      ; Draw 1-8 in gray
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         TDC             ; Clear A
         LDA $1D4E       ; Game options
         AND #$0F        ; Get wallpaper
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C34123,X  ; Tilemap ptr
         STA $F7         ; Set position
         SEP #$20        ; 8-bit A
         LDA $1D4E       ; Game options
         AND #$0F        ; Get wallpaper
         CLC             ; ...
         ADC.B #!num1    ; Convert to text
         STA $F9         ; Add to string
         STZ $FA         ; End string
C34116:  LDY #$00F7      ; 00/00F7
         STY $E7         ; Set src LBs
         LDA #$00        ; Bank: 00
         STA $E9         ; Set src HB
         JSR C302FF      ; Draw user value
         RTS

; Tilemap pointers for wallpaper values
C34123:  dw $43A5        ; 1
         dw $43A9        ; 2
         dw $43AD        ; 3
         dw $43B1        ; 4
         dw $43B5        ; 5
         dw $43B9        ; 6
         dw $43BD        ; 7
         dw $43C1        ; 8

; Draw wallpaper palette and arrow in Config
C34133:  LDA #$3C        ; Palette 7
         STA $29         ; Set tile info
         LDY #C34AC9     ; Text pointer
         JSR C302F9      ; Draw palette
         LDY #C3419D     ; Text pointer
         JSR C302F9      ; Erase arrow
         TDC             ; Clear A
         LDA $1D54       ; Game options
         AND #$38        ; Viewed color
         BEQ C34171      ; Branch if font
         LSR A           ; Put in b2-b4
         LSR A           ; Put in b1-b3
         TAX             ; Index it
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         REP #$20        ; 16-bit A
         LDA.L C3418D,X  ; Text pointer
         STA $E7         ; Set src LBs
         SEP #$20        ; 8-bit A
         LDA #$C3        ; Bank: C3
         STA $E9         ; Set src HB
         JSR C302FF      ; Draw arrow
         LDA #$28        ; Palette 2
         STA $29         ; Color: Gray
         JSR C3417F      ; Draw "Font"
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         JMP C34186      ; Draw "Window"

; Fork: Viewing font
C34171:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         JSR C3417F      ; Draw "Font"
         LDA #$28        ; Palette 2
         STA $29         ; Color: Gray
         JMP C34186      ; Draw "Window"

; Fork: Draw "Font"
C3417F:  LDY #C34AB3     ; Text pointer
         JSR C302F9      ; Draw "Font"
         RTS

; Fork: Draw "Window"
C34186:  LDY #C34ABA     ; Text pointer
         JSR C302F9      ; Draw "Window"
         RTS

; Text pointers for color selection arrow
C3418D:  dw C3419D       ; Font...
         dw C341A7       ; Window 1
         dw C341AB       ; Window 2
         dw C341AF       ; Window 3
         dw C341B3       ; Window 4
         dw C341B7       ; Window 5
         dw C341BB       ; Window 6
         dw C341BF       ; Window 7

; Positioned spaces for blanking color selection arrow
C3419D:  dw $44F5 : db "       ",$00

; Positioned arrows for wallpaper colors
C341A7:  dw $44F5 : db !up,$00 ; Color 1
C341AB:  dw $44F7 : db !up,$00 ; Color 2
C341AF:  dw $44F9 : db !up,$00 ; Color 3
C341B3:  dw $44FB : db !up,$00 ; Color 4
C341B7:  dw $44FD : db !up,$00 ; Color 5
C341BB:  dw $44FF : db !up,$00 ; Color 6
C341BF:  dw $4501 : db !up,$00 ; Color 7

; Draw RGB gauges and values in Config menu
C341C3:  JSR C33950      ; Reset gauges
         TDC             ; Clear A
         LDA $1D4E       ; Game options
         AND #$0F        ; Get wallpaper
         STA $4202       ; Set multiplicand
         LDA #$0E        ; Palette size
         STA $4203       ; Set multiplier
         LDA $1D54       ; Game options
         AND #$38        ; Viewed color
         BEQ C341E7      ; Branch if font
         LSR A           ; Put in b2-b4
         LSR A           ; Put in b1-b3
         CLC             ; ...
         ADC $4216       ; Add product
         TAX             ; Index sum
         LDY $1D55,X     ; Skin color
         BRA C341EA      ; Skip a line
C341E7:  LDY $1D55       ; Font color
C341EA:  STY $9A         ; Memorize it
         JSR C341FE      ; Separate RGB
         JSR C34263      ; Draw B info
         JSR C341FE      ; Separate RGB
         JSR C34250      ; Draw G info
         JSR C341FE      ; Separate RGB
         JMP C3423D      ; Draw R info

; Separate RGB components for color in Config menu
C341FE:  LDY $9A         ; Color
         STY $E7         ; Memorize it
         LDA $E7         ; Color LB
         AND #$1F        ; Get red
         STA $E2         ; Memorize it
         LDA $E8         ; Color HB
         AND #$7C        ; Get blue
         LSR A           ; Shift bits
         LSR A           ; Now 0-31
         STA $E0         ; Memorize it
         REP #$20        ; 16-bit A
         LDA $E7         ; Color
         AND #$03E0      ; Get green
         LSR A           ; ÷2
         LSR A           ; ÷4
         LSR A           ; ÷8
         LSR A           ; ÷16
         LSR A           ; Now 0-31
         SEP #$20        ; 8-bit A
         STA $E1         ; Memorize it
         RTS

; Merge RGB components of updated color
C34221:  LDA $E0         ; Blue
         ASL A           ; x2
         ASL A           ; x4
         STA $E8         ; Memorize it
         LDA $E2         ; Red
         STA $E7         ; Memorize it
         TDC             ; Clear A
         LDA $E1         ; Green
         REP #$20        ; 16-bit A
         ASL A           ; x2
         ASL A           ; x4
         ASL A           ; x8
         ASL A           ; x16
         ASL A           ; x32
         ORA $E7         ; Add R&B
         STA $009A       ; Memorize it
         SEP #$20        ; 8-bit A
         RTS

; Draw value and fill gauge for red component
C3423D:  REP #$20        ; 16-bit A
         LDA #$452F      ; Tilemap ptr
         STA $7E9E89     ; Set gauge pos
         SEP #$20        ; 8-bit A
         LDA $E2         ; Red value
         LDX #$4529      ; Tilemap ptr
         JMP C34276      ; Draw text

; Draw value and fill gauge for green component
C34250:  REP #$20        ; 16-bit A
         LDA #$45AF      ; Tilemap ptr
         STA $7E9E89     ; Set gauge pos
         SEP #$20        ; 8-bit A
         LDA $E1         ; Green value
         LDX #$45A9      ; Tilemap ptr
         JMP C34276      ; Draw text

; Draw value and fill gauge for blue component
C34263:  REP #$20        ; 16-bit A
         LDA #$462F      ; Tilemap ptr
         STA $7E9E89     ; Set gauge pos
         SEP #$20        ; 8-bit A
         LDA $E0         ; Blue value
         LDX #$4629      ; Tilemap ptr
         JMP C34276      ; Draw text

; Draw value and fill gauge for color component
C34276:  PHA             ; Save value
         PHA             ; Do it again
         PHX             ; Save position
         JSR C304E0      ; Convert value
         PLX             ; Text position
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         JSR C304B6      ; Draw 2 digits
         LDX #$9E8B      ; 7E/9E8B
         STX $2181       ; Set WRAM LBs
         PLA             ; Color value
         XBA             ; Switch to HB
         LDA $00         ; Clear it
         XBA             ; Switch to LB
         LSR A           ; ÷2
         LSR A           ; ÷4
         TAX             ; Set counter
         BEQ C3429C      ; Branch if 0
C34294:  LDA.B #!bar8    ; Full tile char
         STA $2180       ; Add to string
         DEX             ; One less tile
         BNE C34294      ; Loop till last
C3429C:  PLA             ; Color component
         AND #$03        ; Extremity size
         TAX             ; Index it
         LDA.L C342BE,X  ; Partial tile
         STA $2180       ; Add to string
         STZ $2180       ; End string
         LDA #$30        ; Palette 4
         STA $29         ; Color: Gray
         JMP C342B1      ; ...
C342B1:  LDY #$9E89      ; 7E/9E89
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         JSR C302FF      ; Draw gauge
         RTS

; Text characters for filling color gauge
C342BE:  db !bar0        ; Empty tile
         db !bar2        ; 1/4 full
         db !bar4        ; 2/4 full
         db !bar6        ; 3/4 full

; 47: Initialize Cmd.Set menu
C342C2:  JSR C3352F      ; Reset/Stop stuff
         JSR C3442C      ; Draw menu
         JSR C3466F      ; Set to shift text
         JSR C345B6      ; Load navig data
         JSR C345BF      ; Relocate cursor
         JSR C307B0      ; Queue cursor OAM
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         LDA #$48        ; C3/42DF
         STA $27         ; Queue: Pick char
         JMP C33541      ; BRT:1 + NMI

; 48: Handle Cmd.Set menu member selection
C342DF:  JSR C345BC      ; Handle D-Pad
         LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C34310      ; Branch if not
         TDC             ; Clear A
         LDA $4B         ; Selected member
         CMP #$04        ; Chose Arrange?
         BEQ C34326      ; Sort if so
         TAX             ; Index member
         LDA $69,X       ; Nobody there?
         BMI C3430A      ; Fail if so
         JSR C30EB2      ; Sound: Click
         LDA $4E         ; Cursor row
         STA $5E         ; Set return row
         LDA $4B         ; List slot
         STA $64         ; Set member slot
         JSR C345D4      ; Load navig data
         JSR C345DA      ; Relocate cursor
         LDA #$62        ; C3/4338
         STA $26         ; Next: Cmd choice
         RTS

; Fork: Play buzzer
C3430A:  JSR C30EC0      ; Play buzzer
         JSR C3305D      ; Pixelate screen

; Fork: Handle B and Start
C34310:  LDA $09         ; No-autofire keys
         BIT #$10        ; Pushing Start?
         BNE C3431C      ; Branch if so
         LDA $09         ; ...
         BIT #$80        ; Pushing B?
         BEQ C34325      ; Exit if not
C3431C:  JSR C30EA9      ; Sound: Cursor
         LDA #$0D        ; C3/1C7D
         STA $27         ; Queue Config
         STZ $26         ; Next: Fade-out
C34325:  RTS

; Fork: Reset command order
C34326:  JSR C30EB2      ; Sound: Click
         JSR C30F39      ; Queue text upload
         JSR C343D0      ; Reset member 1
         JSR C343D8      ; Reset member 2
         JSR C343E1      ; Reset member 3
         JMP C343EA      ; Reset member 4

; 62: Handle Cmd.Set menu command choice 1
C34338:  JSR C34602      ; Handle D-Pad
         LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C34359      ; Branch if not
         JSR C30EB2      ; Sound: Click
         LDA $4B         ; Cursor slot
         STA $28         ; Set blinker's
         JSR C32F06      ; Create blinker
         LDA #$63        ; C3/4376
         STA $26         ; Next: Choice 2
         TDC             ; Clear A
         LDA $64         ; Selected member
         ASL A           ; Double it
         TAX             ; Index it
         LDY $6D,X       ; Actor's address
         STY $67         ; Memorize it
         RTS

; Fork: Handle B
C34359:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C34375      ; Exit if not
         JSR C30EA9      ; Sound: Cursor
         JSR C345B6      ; Load navig data
         LDA $5E         ; Return position
         STA $4E         ; Set cursor row
         JSR C345BF      ; Relocate cursor
         LDA $4E         ; ...
         STA $5E         ; ...
         LDA #$48        ; C3/42DF
         STA $26         ; Next: Pick char
         RTS             ; ...
C34375:  RTS

; 63: Handle Cmd.Set menu command choice 2
C34376:  JSR C34602      ; Handle D-Pad
         LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C343BD      ; Branch if not
         JSR C30EB2      ; Sound: Click
         TDC             ; Clear A
         LDA $4B         ; Cursor's slot
         REP #$21        ; 16-bit A; C-
         ADC $67         ; Add actor's adr
         TAY             ; Index sum
         PHY             ; Memorize it
         SEP #$20        ; 8-bit A
         LDA $0016,Y     ; Second command
         STA $E0         ; Memorize it
         TDC             ; Clear A
         LDA $28         ; Blinker's slot
         REP #$21        ; 16-bit A; C-
         ADC $67         ; Add actor's adr
         TAY             ; Index sum
         SEP #$20        ; 8-bit A
         LDA $0016,Y     ; First command
         STA $E1         ; Memorize it
         LDA $E0         ; Second command
         STA $0016,Y     ; Replace first
         PLY             ; Point to second
         LDA $E1         ; First command
         STA $0016,Y     ; Replace second
         JSR C344B4      ; Draw char 1 text
         JSR C344ED      ; Draw char 2 text
         JSR C34526      ; Draw char 3 text
         JSR C3455F      ; Draw char 4 text
         JSR C30F39      ; Queue text upload
         BRA C343C6      ; Next: Choice 1

; Fork: Handle B
C343BD:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C343CF      ; Exit if not
         JSR C30EA9      ; Sound: Cursor
C343C6:  LDA #$05        ; Blinker: Off
         TRB $46         ; Set menu flag
         LDA #$62        ; C3/4338
         STA $26         ; Next: Choice 1
         RTS             ; ...
C343CF:  RTS

; Reset command list for member 1
C343D0:  LDX $00         ; Point to $6D
         JSR C343F3      ; Reset commands
         JMP C344B4      ; Redraw text

; Reset command list for member 2
C343D8:  LDX #$0002      ; Point to $6F
         JSR C343F3      ; Reset commands
         JMP C344ED      ; Redraw text

; Reset command list for member 3
C343E1:  LDX #$0004      ; Point to $71
         JSR C343F3      ; Reset commands
         JMP C34526      ; Redraw text

; Reset command list for member 4
C343EA:  LDX #$0006      ; Point to $73
         JSR C343F3      ; Reset commands
         JMP C3455F      ; Redraw text

; Reset member's battle command list
C343F3:  LDY $6D,X       ; Actor's address
         BEQ C3442A      ; Exit if nobody
         TDC             ; Clear A
         LDA $0000,Y     ; Actor
         CMP #$0C        ; Gogo?
         BEQ C3442B      ; Exit if so
         STA $4202       ; Set multiplicand
         LDA #$16        ; Actor data size
         STA $4203       ; Set multiplier
         NOP
         NOP
         NOP
         NOP
         LDX $4216       ; Index product
         LDA $ED7CA2,X   ; Command 1
         STA $0016,Y     ; Set actor's
         LDA $ED7CA3,X   ; Command 2
         STA $0017,Y     ; Set actor's
         LDA $ED7CA4,X   ; Command 3
         STA $0018,Y     ; Set actor's
         LDA $ED7CA5,X   ; Command 4
         STA $0019,Y     ; Set actor's
C3442A:  RTS             ; ...
C3442B:  RTS

; Draw Cmd.Set menu
C3442C:  JSR C36A28      ; Clear BG2 map A
         LDY #C34490     ; C3/4490
         JSR C30341      ; Draw cmd box A
         LDY #C34494     ; C3/4494
         JSR C30341      ; Draw cmd box B
         LDY #C34498     ; C3/4498
         JSR C30341      ; Draw cmd box C
         LDY #C3449C     ; C3/449C
         JSR C30341      ; Draw cmd box D
         LDY #C344A0     ; C3/44A0
         JSR C30341      ; Draw name box A
         LDY #C344A4     ; C3/44A4
         JSR C30341      ; Draw name box B
         LDY #C344A8     ; C3/44A8
         JSR C30341      ; Draw name box C
         LDY #C344AC     ; C3/44AC
         JSR C30341      ; Draw name box D
         LDY #C344B0     ; C3/44B0
         JSR C30341      ; Draw Arrange box
         JSR C30E52      ; Upload windows
         JSR C36A15      ; Clear BG1 map A
         JSR C36A19      ; Clear BG1 map B
         JSR C36A3C      ; Clear BG3 map A
         JSR C36A41      ; Clear BG3 map B
         LDA #$30        ; Palette 4
         STA $29         ; Color: Blue
         LDY #C34AF1     ; Text pointer
         JSR C302F9      ; Draw "Arrange"
         JSR C344B4      ; Draw char 1 text
         JSR C344ED      ; Draw char 2 text
         JSR C34526      ; Draw char 3 text
         JSR C3455F      ; Draw char 4 text
         JSR C30E28      ; Upload BG1 A+B
         JMP C30E6E      ; Upload BG3 A+B

; Window layout for Cmd.Set menu
C34490:  dw $591F,$0412  ; 20x06 at $591F (Command set A)
C34494:  dw $5A9F,$0412  ; 20x06 at $5A9F (Command set B)
C34498:  dw $5C1F,$0412  ; 20x06 at $5C1F (Command set C)
C3449C:  dw $5D9F,$0412  ; 20x06 at $5D9F (Command set D)
C344A0:  dw $590B,$0408  ; 10x06 at $590B (Member name A)
C344A4:  dw $5A8B,$0408  ; 10x06 at $5A8B (Member name B)
C344A8:  dw $5C0B,$0408  ; 10x06 at $5C0B (Member name C)
C344AC:  dw $5D8B,$0408  ; 10x06 at $5D8B (Member name D)
C344B0:  dw $588B,$0108  ; 10x03 at $588B (Arrange)

; Draw Cmd.Set menu text for member 1
C344B4:  LDA $69         ; Actor in slot
         BMI C344EC      ; Exit if none
         JSL $C20006     ; Load gear data
         LDX $6D         ; Actor's address
         STX $67         ; Memorize it
         LDA #$30        ; Palette 4
         STA $29         ; Color: Blue
         LDY #$798F      ; Text position
         JSR C334CF      ; Draw actor name
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDY #$7A0F      ; Text position
         JSR C334E5      ; Actor class...
         LDY #$79AD      ; Text position
         JSR C34598      ; Draw command 1
         LDY #$7A23      ; Text position
         JSR C3459E      ; Draw command 2
         LDY #$7A37      ; Text position
         JSR C345A5      ; Draw command 3
         LDY #$7AAD      ; Text position
         JSR C345AD      ; Draw command 4
C344EC:  RTS

; Draw Cmd.Set menu text for member 2
C344ED:  LDA $6A         ; Actor in slot
         BMI C34525      ; Exit if none
         JSL $C20006     ; Load gear data
         LDX $6F         ; Actor's address
         STX $67         ; Memorize it
         LDA #$30        ; Palette 4
         STA $29         ; Color: Blue
         LDY #$7B4F      ; Text position
         JSR C334CF      ; Draw actor name
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDY #$7BCF      ; Text position
         JSR C334E5      ; Actor class...
         LDY #$7B6D      ; Text position
         JSR C34598      ; Draw command 1
         LDY #$7BE3      ; Text position
         JSR C3459E      ; Draw command 2
         LDY #$7BF7      ; Text position
         JSR C345A5      ; Draw command 3
         LDY #$7C6D      ; Text position
         JSR C345AD      ; Draw command 4
C34525:  RTS

; Draw Cmd.Set menu text for member 3
C34526:  LDA $6B         ; Actor in slot
         BMI C3455E      ; Exit if none
         JSL $C20006     ; Load gear data
         LDX $71         ; Actor's address
         STX $67         ; Memorize it
         LDA #$30        ; Palette 4
         STA $29         ; Color: Blue
         LDY #$7D0F      ; Text position
         JSR C334CF      ; Draw actor name
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDY #$7D8F      ; Text position
         JSR C334E5      ; Actor class...
         LDY #$7D2D      ; Text position
         JSR C34598      ; Draw command 1
         LDY #$7DA3      ; Text position
         JSR C3459E      ; Draw command 2
         LDY #$7DB7      ; Text position
         JSR C345A5      ; Draw command 3
         LDY #$7E2D      ; Text position
         JSR C345AD      ; Draw command 4
C3455E:  RTS

; Draw Cmd.Set menu text for member 4
C3455F:  LDA $6C         ; Actor in slot
         BMI C34597      ; Exit if none
         JSL $C20006     ; Load gear data
         LDX $73         ; Actor's address
         STX $67         ; Memorize it
         LDA #$30        ; Palette 4
         STA $29         ; Color: Blue
         LDY #$7ECF      ; Text position
         JSR C334CF      ; Draw actor name
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDY #$7F4F      ; Text position
         JSR C334E5      ; Actor class...
         LDY #$7EED      ; Text position
         JSR C34598      ; Draw command 1
         LDY #$7F63      ; Text position
         JSR C3459E      ; Draw command 2
         LDY #$7F77      ; Text position
         JSR C345A5      ; Draw command 3
         LDY #$7FED      ; Text position
         JSR C345AD      ; Draw command 4
C34597:  RTS

; Draw member's 1st command in Cmd.Set menu
C34598:  JSR C33519      ; Set pos/WRAM/Y
         JMP C35EE1      ; Draw command

; Draw member's 2nd command in Cmd.Set menu
C3459E:  JSR C33519      ; Set pos/WRAM/Y
         INY             ; Point to cmd 2
         JMP C35EE1      ; Draw command

; Draw member's 3rd command in Cmd.Set menu
C345A5:  JSR C33519      ; Set pos/WRAM/Y
         INY             ; Point to cmd 2
         INY             ; Point to cmd 3
         JMP C35EE1      ; Draw command

; Draw member's 4th command in Cmd.Set menu
C345AD:  JSR C33519      ; Set pos/WRAM/Y
         INY             ; Point to cmd 2
         INY             ; Point to cmd 3
         INY             ; Point to cmd 4
         JMP C35EE1      ; Draw command

; Load navigation data for Cmd.Set menu's actor list
C345B6:  LDY #C345C5     ; C3/45C5
         JMP C305FE      ; Load navig data

; Handle D-Pad for Cmd.Set menu's actor list
C345BC:  JSR C3072D      ; Handle D-Pad
C345BF:  LDY #C345CA     ; C3/45CA
         JMP C30640      ; Relocate cursor

; Navigation data for Cmd.Set menu's actor list
C345C5:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $05          ; 5 rows

; Cursor positions for Cmd.Set menu's actor list
C345CA:  dw $2008        ; Member 1
         dw $5008        ; Member 2
         dw $8008        ; Member 3
         dw $B008        ; Member 4
         dw $0C08        ; Arrange

; Load navigation data for Cmd.Set menu's command list
C345D4:  LDY #C3464A     ; C3/464A
         JMP C305FE      ; Load navig data

; Relocate cursor in Cmd.Set menu's command list
C345DA:  TDC             ; Clear A
         LDA $64         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C345E2,X)  ; Relocate cursor

; Jump table for the above
C345E2:  dw C345EA       ; Member 1
         dw C345F0       ; Member 2
         dw C345F6       ; Member 3
         dw C345FC       ; Member 4

; Relocate cursor in Cmd.Set menu's command list for member 1
C345EA:  LDY #C3464F     ; C3/464F
         JMP C30640      ; Relocate cursor

; Relocate cursor in Cmd.Set menu's command list for member 2
C345F0:  LDY #C34657     ; C3/4657
         JMP C30640      ; Relocate cursor

; Relocate cursor in Cmd.Set menu's command list for member 3
C345F6:  LDY #C3465F     ; C3/465F
         JMP C30640      ; Relocate cursor

; Relocate cursor in Cmd.Set menu's command list for member 4
C345FC:  LDY #C34667     ; C3/4667
         JMP C30640      ; Relocate cursor

; Handle D-Pad and cursor for Cmd.Set menu's command list
C34602:  JSR C34615      ; Handle D-Pad
         TDC             ; Clear A
         LDA $64         ; Member
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C3460D,X)  ; Relocate cursor

; Jump table for the above
C3460D:  dw C345EA       ; Member 1
         dw C345F0       ; Member 2
         dw C345F6       ; Member 3
         dw C345FC       ; Member 4

; Handle D-Pad for Cmd.Set menu's command list
C34615:  STZ $4D         ; Cursor col: 1st
         LDA $0B         ; Semi-auto keys
         BIT #$08        ; Pushing up?
         BEQ C34622      ; Branch if not
         STZ $4E         ; Cursor slot: Top
         JSR C30EA3      ; Sound: Cursor
C34622:  LDA $0B         ; Semi-auto keys
         BIT #$04        ; Pushing down?
         BEQ C3462F      ; Branch if not
         LDA #$03        ; Slot: Bottom
         STA $4E         ; Set cursor slot
         JSR C30EA3      ; Sound: Cursor
C3462F:  LDA $0B         ; Semi-auto keys
         BIT #$02        ; Pushing left?
         BEQ C3463C      ; Branch if not
         LDA #$01        ; Slot: Left
         STA $4E         ; Set cursor slot
         JSR C30EA3      ; Sound: Cursor
C3463C:  LDA $0B         ; Semi-auto keys
         BIT #$01        ; Pushing right?
         BEQ C34649      ; Exit if not
         LDA #$02        ; Slot: Right
         STA $4E         ; Set cursor slot
         JSR C30EA3      ; Sound: Cursor
C34649:  RTS

; Navigation data for Cmd.Set menu's command list
C3464A:  db $81          ; Never wraps
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $04          ; 4 rows

; Cursor positions for member 1 in Cmd.Set menu
C3464F:  dw $2080        ; Command 1
         dw $2C58        ; Command 2
         dw $2CA8        ; Command 3
         dw $3880        ; Command 4

; Cursor positions for member 2 in Cmd.Set menu
C34657:  dw $5080        ; Command 1
         dw $5C58        ; Command 2
         dw $5CA8        ; Command 3
         dw $6880        ; Command 4

; Cursor positions for member 3 in Cmd.Set menu
C3465F:  dw $8080        ; Command 1
         dw $8C58        ; Command 2
         dw $8CA8        ; Command 3
         dw $9880        ; Command 4

; Cursor positions for member 4 in Cmd.Set menu
C34667:  dw $B080        ; Command 1
         dw $BC58        ; Command 2
         dw $BCA8        ; Command 3
         dw $C880        ; Command 4

; Set to condense text in Cmd.Set menu
C3466F:  LDA #$02        ; 1Rx2B to PPU
         STA $4350       ; Set DMA mode
         LDA #$12        ; $2112
         STA $4351       ; To BG3 V-Scroll
         LDY #C3468E     ; C3/468E
         STY $4352       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4354       ; Set src HB
         LDA #$C3        ; ...
         STA $4357       ; Set indir HB
         LDA #$20        ; Channel: 5
         TSB $43         ; Queue HDMA-5
         RTS

; Text shifting table for the above
C3468E:  db $1F,$00,$00  ; Arrange
         db $0C,$04,$00  ; Row 1
         db $0C,$08,$00  ; Row 2
         db $24,$0C,$00  ; Row 3, row 4
         db $0C,$10,$00  ; Row 5
         db $24,$14,$00  ; Row 6, row 7
         db $0C,$18,$00  ; Row 8
         db $24,$1C,$00  ; Row 9, row 10
         db $0C,$20,$00  ; Row 11
         db $24,$24,$00  ; Row 12
         db $00          ; End

; 4B: Initialize Controller menu
C346AD:  JSR C3352F      ; Reset/Stop stuff
         JSR C346F5      ; Draw menu
         JSR C348A8      ; Queue Win2 HDMA
         JSR C348D7      ; Load navig data
         JSR C348E0      ; Relocate cursor
         JSR C307B0      ; Queue cursor OAM
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         LDA #$4C        ; C3/46CA
         STA $27         ; Queue: Sustain menu
         JMP C33541      ; BRT:1 + NMI

; 4C: Sustain Controller menu
C346CA:  JSR C30F39      ; Queue BG3 upload
         JSR C348DD      ; Handle D-Pad
         LDA $09         ; No-autofire keys
         BIT #$10        ; Pushing Start?
         BNE C346DC      ; Branch if so
         LDA $09         ; ...
         BIT #$80        ; Pushing B?
         BEQ C346E6      ; Branch if not
C346DC:  JSR C30EA9      ; Sound: Cursor
         LDA #$0D        ; C3/1C7D
         STA $27         ; Queue Config menu
         STZ $26         ; Next: Fade-out
         RTS

; Fork: Handle left and right
C346E6:  LDA $0B         ; Semi-auto keys
         BIT #$01        ; Pushing right?
         BNE C346F2      ; Branch if so
         LDA $0B         ; ...
         BIT #$02        ; Pushing left?
         BEQ C346F4      ; Exit if not
C346F2:  BRA C34717      ; Handle changes
C346F4:  RTS

; Draw Controller menu
C346F5:  LDY #C348F3     ; C3/48F3
         JSR C30341      ; Draw menu window
         JSR C30E52      ; Upload window
         LDA #$30        ; Palette 4
         STA $29         ; Color: Blue
         LDY #C34AFB     ; Text pointer
         JSR C302F9      ; Draw "Controller"
         JSR C347B4      ; Draw char 1 text
         JSR C347F1      ; Draw char 2 text
         JSR C3482E      ; Draw char 3 text
         JSR C3486B      ; Draw char 4 text
         JMP C30E6E      ; Upload text

; Handle changes in Controller menu
C34717:  TDC             ; Clear A
         LDA $4B         ; Member slot
         TAX             ; Index it
         LDA $69,X       ; Nobody there?
         BMI C34729      ; Exit if so
         JSR C30EA3      ; Sound: Cursor
         LDA $4B         ; Cursor slot
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C3472A,X)  ; Apply changes
C34729:  RTS

; Jump table for controller assignments
C3472A:  dw C34732       ; Member 1
         dw C34751       ; Member 2
         dw C34772       ; Member 3
         dw C34793       ; Member 4

; Update controller assignment for member 1
C34732:  LDA $1D4F       ; ...
         AND #$01        ; ...
         LDA $0B         ; Semi-auto keys
         BIT #$01        ; Pushing right?
         BEQ C34747      ; Branch if not
         LDA #$01        ; Assign Cntlr2
         ORA $1D4F       ; Merge pad data
         STA $1D4F       ; Update options
         BRA C347B4      ; Redraw text
C34747:  LDA $1D4F       ; Joypad options
         AND #$FE        ; Assign Cntlr1
         STA $1D4F       ; Save changes
         BRA C347B4      ; Redraw text

; Update controller assignment for member 2
C34751:  LDA $1D4F       ; ...
         AND #$02        ; ...
         LDA $0B         ; Semi-auto keys
         BIT #$01        ; Pushing right?
         BEQ C34767      ; Branch if not
         LDA #$02        ; Assign Cntlr2
         ORA $1D4F       ; Merge pad data
         STA $1D4F       ; Update options
         JMP C347F1      ; Redraw text
C34767:  LDA $1D4F       ; Joypad options
         AND #$FD        ; Assign Cntlr1
         STA $1D4F       ; Save changes
         JMP C347F1      ; Redraw text

; Update controller assignment for member 3
C34772:  LDA $1D4F       ; ...
         AND #$04        ; ...
         LDA $0B         ; Semi-auto keys
         BIT #$01        ; Pushing right?
         BEQ C34788      ; Branch if not
         LDA #$04        ; Assign Cntlr2
         ORA $1D4F       ; Merge pad data
         STA $1D4F       ; Update options
         JMP C3482E      ; Redraw text
C34788:  LDA $1D4F       ; Joypad options
         AND #$FB        ; Assign Cntlr1
         STA $1D4F       ; Save changes
         JMP C3482E      ; Redraw text

; Update controller assignment for member 4
C34793:  LDA $1D4F       ; ...
         AND #$08        ; ...
         LDA $0B         ; Semi-auto keys
         BIT #$01        ; Pushing right?
         BEQ C347A9      ; Branch if not
         LDA #$08        ; Assign Cntlr2
         ORA $1D4F       ; Merge pad data
         STA $1D4F       ; Update options
         JMP C3486B      ; Redraw text
C347A9:  LDA $1D4F       ; Joypad options
         AND #$F7        ; Assign Cntlr1
         STA $1D4F       ; Save changes
         JMP C3486B      ; Redraw text

; Draw Controller menu text for member 1
C347B4:  LDA $69         ; Nobody here?
         BMI C347F0      ; Exit if so
         LDX $6D         ; Actor's address
         STX $67         ; Memorize it
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDY #$7BCF      ; Text position
         JSR C334CF      ; Draw actor name
         LDA $1D4F       ; Assigned pad
         AND #$01        ; Player 1's?
         BEQ C347D6      ; Branch if so
         LDA #$24        ; Color: Gray
         JSR C347DF      ; Draw "Cntlr1"
         LDA #$20        ; Color: User's
         BRA C347E8      ; Draw "Cntlr2"

; Fork: Highlight Cntlr1
C347D6:  LDA #$20        ; Color: User's
         JSR C347DF      ; Draw "Cntlr1"
         LDA #$24        ; Color: Gray
         BRA C347E8      ; Draw "Cntlr2"

; Fork: Draw "Cntlr1"
C347DF:  STA $29         ; Set palette
         LDY #C34B08     ; Text pointer
         JSR C302F9      ; Draw "Cntlr1"
         RTS

; Fork: Draw "Cntlr2"
C347E8:  STA $29         ; Set palette
         LDY #C34B11     ; Text pointer
         JSR C302F9      ; Draw "Cntlr2"
C347F0:  RTS

; Draw Controller menu text for member 2
C347F1:  LDA $6A         ; Nobody here?
         BMI C3482D      ; Exit if so
         LDX $6F         ; Actor's address
         STX $67         ; Memorize it
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDY #$7C4F      ; Text position
         JSR C334CF      ; Draw actor name
         LDA $1D4F       ; Assigned pad
         AND #$02        ; Player 1's?
         BEQ C34813      ; Branch if so
         LDA #$24        ; Color: Gray
         JSR C3481C      ; Draw "Cntlr1"
         LDA #$20        ; Color: User's
         BRA C34825      ; Draw "Cntlr2"

; Fork: Highlight Cntlr1
C34813:  LDA #$20        ; Color: User's
         JSR C3481C      ; Draw "Cntlr1"
         LDA #$24        ; Color: Gray
         BRA C34825      ; Draw "Cntlr2"

; Fork: Draw "Cntlr1"
C3481C:  STA $29         ; Set palette
         LDY #C34B1A     ; Text pointer
         JSR C302F9      ; Draw "Cntlr1"
         RTS

; Fork: Draw "Cntlr2"
C34825:  STA $29         ; Set palette
         LDY #C34B23     ; Text pointer
         JSR C302F9      ; Draw "Cntlr2"
C3482D:  RTS

; Draw Controller menu text for member 3
C3482E:  LDA $6B         ; Nobody here?
         BMI C3486A      ; Exit if so
         LDX $71         ; Actor's address
         STX $67         ; Memorize it
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDY #$7CCF      ; Text position
         JSR C334CF      ; Draw actor name
         LDA $1D4F       ; Assigned pad
         AND #$04        ; Player 1's?
         BEQ C34850      ; Branch if so
         LDA #$24        ; Color: Gray
         JSR C34859      ; Draw "Cntlr1"
         LDA #$20        ; Color: User's
         BRA C34862      ; Draw "Cntlr2"

; Fork: Highlight Cntlr1
C34850:  LDA #$20        ; Color: User's
         JSR C34859      ; Draw "Cntlr1"
         LDA #$24        ; Color: Gray
         BRA C34862      ; Draw "Cntlr2"

; Fork: Draw "Cntlr1"
C34859:  STA $29         ; Set palette
         LDY #C34B2C     ; Text pointer
         JSR C302F9      ; Draw "Cntlr1"
         RTS

; Fork: Draw "Cntlr2"
C34862:  STA $29         ; Set palette
         LDY #C34B35     ; Text pointer
         JSR C302F9      ; Draw "Cntlr2"
C3486A:  RTS

; Draw Controller menu text for member 4
C3486B:  LDA $6C         ; Nobody here?
         BMI C348A7      ; Exit if so
         LDX $73         ; Actor's address
         STX $67         ; Memorize it
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDY #$7D4F      ; Text position
         JSR C334CF      ; Draw actor name
         LDA $1D4F       ; Assigned pad
         AND #$08        ; Player 1's?
         BEQ C3488D      ; Branch if so
         LDA #$24        ; Color: Gray
         JSR C34896      ; Draw "Cntlr1"
         LDA #$20        ; Color: User's
         BRA C3489F      ; Draw "Cntlr2"

; Fork: Highlight Cntlr1
C3488D:  LDA #$20        ; Color: User's
         JSR C34896      ; Draw "Cntlr1"
         LDA #$24        ; Color: Gray
         BRA C3489F      ; Draw "Cntlr2"

; Fork: Draw "Cntlr1"
C34896:  STA $29         ; Set palette
         LDY #C34B3E     ; Text pointer
         JSR C302F9      ; Draw "Cntlr1"
         RTS

; Fork: Draw "Cntlr2"
C3489F:  STA $29         ; Set palette
         LDY #C34B47     ; Text pointer
         JSR C302F9      ; Draw "Cntlr2"
C348A7:  RTS

; Set Window 2 positions per scanline for Controller menu
C348A8:  LDA #$01        ; 2Rx1B to PPU
         STA $4350       ; Set DMA mode
         LDA #$28        ; $2128, $2129
         STA $4351       ; To Win 2 L+R
         LDY #C348C7     ; C3/48C7
         STY $4352       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4354       ; Set src HB
         LDA #$C3        ; ...
         STA $4357       ; Set indir HB
         LDA #$20        ; Channel: 5
         TSB $43         ; Queue HDMA-5
         RTS

; Window 2 positions per scanline for Controller menu
C348C7:  db $27,$FF,$FF  ; 255, 255
         db $30,$08,$F7  ; 8, 247
         db $68,$FF,$FF  ; 255, 255
         db $10,$08,$F7  ; 8, 247
         db $10,$FF,$FF  ; 255, 255
         db $00          ; End

; Load navigation data for Controller menu
C348D7:  LDY #C348E6     ; C3/48E6
         JMP C305FE      ; Load navig data

; Handle D-Pad for Controller menu
C348DD:  JSR C3072D      ; Handle D-Pad
C348E0:  LDY #C348EB     ; C3/48EB
         JMP C30640      ; Relocate cursor

; Navigation data for Controller menu
C348E6:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $04          ; 4 rows

; Cursor positions for Controller menu
C348EB:  dw $7B50        ; Member 1
         dw $8B50        ; Member 2
         dw $9B50        ; Member 3
         dw $AB50        ; Member 4

; Window layout for Controller menu
C348F3:  dw $5B0B,$0B1C  ; 30x13 at $5B0B

; Forget memorized cursor positions for main menu
C348F7:  TDC             ; Clear A
         TAX             ; Index: 0
C348F9:  STA $022B,X     ; Clear position
         INX             ; Index +1
         CPX #$001F      ; At $024A?
         BNE C348F9      ; Loop if not
         RTS

; Text pointers for Config page 1
C34903:  dw C3490B       ; Controller
         dw C3498A       ; Cursor
C34907:  dw C3491F       ; Fast
         dw C34926       ; Slow

; Positioned text for Config page 1
C3490B:  dw $3D8F : db "Controller",$00
C34918:  dw $39B5 : db "Wait",$00
C3491F:  dw $3A65 : db "Fast",$00
C34926:  dw $3A75 : db "Slow",$00
C3492D:  dw $3B35 : db "Short",$00
C34935:  dw $3BA5 : db "On",$00
C3493A:  dw $3BB5 : db "Off",$00
C34940:  dw $3C25 : db "Stereo",$00
C34949:  dw $3C35 : db "Mono",$00
C34950:  dw $3CB5 : db "Memory",$00
C34959:  dw $3D25 : db "Optimum",$00
C34963:  dw $3DB5 : db "Multiple",$00
C3496E:  dw $3A25 : db "1 2 3 4 5 6",$00
C3497C:  dw $3AA5 : db "1 2 3 4 5 6",$00
C3498A:  dw $3C8F : db "Cursor",$00

; Text pointers for Config page 1
C34993:  dw C349AA       ; Bat.Mode
         dw C349B5       ; Bat.Speed
         dw C349C1       ; Msg.Speed
         dw C349CD       ; Cmd.Set
         dw C349D7       ; Gauge
         dw C349DF       ; Sound
         dw C349E7       ; Reequip

; Positioned text for Config page 1
C349A1:  dw $78F9 : db "Config",$00
C349AA:  dw $398F : db "Bat.Mode",$00
C349B5:  dw $3A0F : db "Bat.Speed",$00
C349C1:  dw $3A8F : db "Msg.Speed",$00
C349CD:  dw $3B0F : db "Cmd.Set",$00
C349D7:  dw $3B8F : db "Gauge",$00
C349DF:  dw $3C0F : db "Sound",$00
C349E7:  dw $3D0F : db "Reequip",$00
C349F1:  dw $39A5 : db "Active",$00
C349FA:  dw $3B25 : db "Window",$00
C34A03:  dw $3CA5 : db "Reset",$00
C34A0B:  dw $3D35 : db "Empty",$00
C34A13:  dw $3DA5 : db "Single",$00

; Text pointers for Config page 2
C34A1C:  dw C34A34       ; Mag.Order
         dw C34A40       ; Window
         dw C34A49       ; Color
C34A22:  dw C34A60       ; «========»
         dw C34A6D       ; «========»
         dw C34A7A       ; «========»
C34A28:  dw C34A87       ; R
         dw C34A8B       ; G
         dw C34A8F       ; B
         dw C34A51       ; A..
         dw C34A56       ; B..
         dw C34A5B       ; C..

; Positioned text for Config page 2
C34A34:  dw $418F : db "Mag.Order",$00
C34A40:  dw $438F : db "Window",$00
C34A49:  dw $440F : db "Color",$00
C34A51:  dw $4225 : db "A",!2dot,$00
C34A56:  dw $42A5 : db "B",!2dot,$00
C34A5B:  dw $4325 : db "C",!2dot,$00
C34A60:  dw $452D : db "«±±±±±±±±»",$00
C34A6D:  dw $45AD : db "«±±±±±±±±»",$00
C34A7A:  dw $462D : db "«±±±±±±±±»",$00
C34A87:  dw $4525 : db "R",$00
C34A8B:  dw $45A5 : db "G",$00
C34A8F:  dw $4625 : db "B",$00
C34A93:  dw $43A5 : db "1 2 3 4 5 6 7 8",$00
C34AA5:  dw $41A5 : db "1 2 3 4 5 6",$00
C34AB3:  dw $4425 : db "Font",$00
C34ABA:  dw $4435 : db "Window",$00
C34AC3:  dw $43FB : db $A5,$47,$79,$00
C34AC9:  dw $44B5 : db !pal1,!pal2,!pal3,!pal4,!pal5,!pal6,!pal7,$00

; Mag.Order strings
C34AD3:  db !whit,"Healing  "
         db !blck,"Attack   "
         db !gray,"Effect   "

; Positioned text for Cmd.Set menu
C34AF1:  dw $78CF : db "Arrange",$00

; Positioned text for Controller menu
C34AFB:  dw $7B4D : db "Controller",$00
C34B08:  dw $7C21 : db "Cntlr1",$00
C34B11:  dw $7C33 : db "Cntlr2",$00
C34B1A:  dw $7CA1 : db "Cntlr1",$00
C34B23:  dw $7CB3 : db "Cntlr2",$00
C34B2C:  dw $7D21 : db "Cntlr1",$00
C34B35:  dw $7D33 : db "Cntlr2",$00
C34B3E:  dw $7DA1 : db "Cntlr1",$00
C34B47:  dw $7DB3 : db "Cntlr2",$00

; Load navigation data for Skills menu
C34B50:  LDY #C34B6F     ; C3/4B6F
         JMP C305FE      ; Load navig data

; Handle D-Pad and cursor memory for Skills menu
C34B56:  JSR C3072D      ; Handle D-Pad
C34B59:  LDY #C34B74     ; C3/4B74
         JSR C30640      ; Relocate cursor
         TDC             ; Clear A
         LDA $28         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA $4D         ; Cursor column
         STA $0236,X     ; Remember it
         LDA $4E         ; Cursor row
         STA $0237,X     ; Remember it
         RTS

; Navigation data for Skills menu
C34B6F:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $01          ; Initial row
         db $01          ; 1 column
         db $07          ; 7 rows

; Cursor positions for Skills menu
C34B74:  dw $1400        ; Espers
         dw $2400        ; Magic
         dw $4400        ; SwdTech
         dw $5400        ; Blitz
         dw $6400        ; Lore
         dw $7400        ; Rage
         dw $8400        ; Dance

; Load navigation data for Magic menu
C34B82:  LDY #C34BA9     ; C3/4BA9
         JMP C305FE      ; Load navig data

; Handle D-Pad and cursor memory for Magic menu
C34B88:  JSR C381C7      ; Handle D-Pad
C34B8B:  LDY #C34BAE     ; C3/4BAE
         JSR C30648      ; Relocate cursor
         TDC             ; Clear A
         LDA $28         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA $4F         ; List column
         STA $023E,X     ; Remember it
         LDA $50         ; List row
         STA $023F,X     ; Remember it
         LDA $28         ; Member slot
         TAX             ; Index it
         LDA $4A         ; Scroll position
         STA $0246,X     ; Remember it
         RTS

; Navigation data for Magic menu
C34BA9:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $02          ; 2 columns
         db $08          ; 8 rows

; Cursor positions for Magic menu
C34BAE:  dw $7408        ; Spell 1
         dw $7470        ; Spell 2
         dw $8008        ; Spell 3
         dw $8070        ; Spell 4
         dw $8C08        ; Spell 5
         dw $8C70        ; Spell 6
         dw $9808        ; Spell 7
         dw $9870        ; Spell 8
         dw $A408        ; Spell 9
         dw $A470        ; Spell 10
         dw $B008        ; Spell 11
         dw $B070        ; Spell 12
         dw $BC08        ; Spell 13
         dw $BC70        ; Spell 14
         dw $C808        ; Spell 15
         dw $C870        ; Spell 16

; Load navigation data for SwdTech, Blitz, or Dance menu
C34BCE:  LDY #C34BDF     ; C3/4BDF
         JMP C305FE      ; Load navig data

; Handle D-Pad for SwdTech, Blitz, or Dance menu
C34BD4:  JSR C3072D      ; Handle D-Pad
C34BD7:  LDY #C34BE4     ; C3/4BE4
         STY $E7         ; ...
         JMP C30640      ; Relocate cursor

; Navigation data for SwdTech, Blitz, and Dance menus
C34BDF:  db $00          ; Wraps on all sides
         db $00          ; Initial column
         db $00          ; Initial row
         db $02          ; 2 columns
         db $04          ; 4 rows

; Cursor positions for SwdTech, Blitz, and Dance menus
C34BE4:  dw $7408        ; Skill 1
         dw $7478        ; Skill 2
         dw $8C08        ; Skill 3
         dw $8C78        ; Skill 4
         dw $A408        ; Skill 5
         dw $A478        ; Skill 6
         dw $BC08        ; Skill 7
         dw $BC78        ; Skill 8

; Load navigation data for Lore menu
C34BF4:  LDY #C34C03     ; C3/4C03
         JMP C305FE      ; Load navig data

; Handle D-Pad for Lore menu
C34BFA:  JSR C381C7      ; Handle D-Pad
C34BFD:  LDY #C34C08     ; C3/4C08
         JMP C30648      ; Relocate cursor

; Navigation data for Lore menu
C34C03:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $08          ; 8 rows

; Cursor positions for Lore menu
C34C08:  dw $7408        ; Spell 1
         dw $8008        ; Spell 2
         dw $8C08        ; Spell 3
         dw $9808        ; Spell 4
         dw $A408        ; Spell 5
         dw $B008        ; Spell 6
         dw $BC08        ; Spell 7
         dw $C808        ; Spell 8

; Load navigation data for Espers menu
C34C18:  LDY #C34C27     ; C3/4C27
         JMP C305FE      ; Load navig data

; Handle D-Pad for Espers menu
C34C1E:  JSR C381C7      ; Handle D-Pad
C34C21:  LDY #C34C2C     ; C3/4C2C
         JMP C30648      ; Relocate cursor

; Navigation data for Espers menu
C34C27:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $02          ; 2 columns
         db $08          ; 8 rows

; Cursor positions for Espers menu
C34C2C:  dw $7408        ; Esper 1
         dw $7478        ; Esper 2
         dw $8008        ; Esper 3
         dw $8078        ; Esper 4
         dw $8C08        ; Esper 5
         dw $8C78        ; Esper 6
         dw $9808        ; Esper 7
         dw $9878        ; Esper 8
         dw $A408        ; Esper 9
         dw $A478        ; Esper 10
         dw $B008        ; Esper 11
         dw $B078        ; Esper 12
         dw $BC08        ; Esper 13
         dw $BC78        ; Esper 14
         dw $C808        ; Esper 15
         dw $C878        ; Esper 16

; Load navigation data for Rage menu
C34C4C:  LDY #C34C5B     ; C3/4C5B
         JMP C305FE      ; Load navig data

; Handle D-Pad for Rage menu
C34C52:  JSR C381C7      ; Handle D-Pad
C34C55:  LDY #C34C60     ; C3/4C60
         JMP C30648      ; Relocate cursor

; Navigation data for Rage menu
C34C5B:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $02          ; 2 columns
         db $08          ; 8 rows

; Cursor positions for Rage menu
C34C60:  dw $7418        ; Rage 1
         dw $7488        ; Rage 2
         dw $8018        ; Rage 3
         dw $8088        ; Rage 4
         dw $8C18        ; Rage 5
         dw $8C88        ; Rage 6
         dw $9818        ; Rage 7
         dw $9888        ; Rage 8
         dw $A418        ; Rage 9
         dw $A488        ; Rage 10
         dw $B018        ; Rage 11
         dw $B088        ; Rage 12
         dw $BC18        ; Rage 13
         dw $BC88        ; Rage 14
         dw $C818        ; Rage 15
         dw $C888        ; Rage 16

; Draw Skills menu, disable individual MP costs in Magic menu
C34C80:  STZ $9E         ; No MP by Magic
         JSR C30F89      ; Stop VRAM DMA B
         LDA #$01        ; 64x32 at $0000
         STA $2107       ; Set BG1 map loc
         JSR C36A28      ; Clear BG2 map A
         JSR C36A2D      ; Clear BG2 map B
         LDY #C34DA4     ; C3/4DA4
         JSR C30341      ; Draw lower box A
         LDY #C34DA0     ; C3/4DA0
         JSR C30341      ; Draw stats box A
         LDY #C34DA8     ; C3/4DA8
         JSR C30341      ; Draw top box A
         LDY #C34D9C     ; C3/4D9C
         JSR C30341      ; Draw option box B
         LDY #C34D98     ; C3/4D98
         JSR C30341      ; Draw option box A
         LDY #C34DB0     ; C3/4DB0
         JSR C30341      ; Draw lower box B
         LDY #C34DAC     ; C3/4DAC
         JSR C30341      ; Draw stats box B
         LDY #C34DB8     ; C3/4DB8
         JSR C30341      ; Draw top box B
         LDY #C34DB4     ; C3/4DB4
         JSR C30341      ; Draw title box
         JSR C30E52      ; Upload windows
         JSR C34D27      ; Draw actor info
         JSR C30E28      ; Upload BG1 A+B
         JSR C36A3C      ; Clear BG3 map A
         JSR C36A41      ; Clear BG3 map B
         JSR C36A46      ; Clear BG3 map C
         JSR C3A662      ; Build desc map
         JSR C34D3D      ; Set skill colors
         LDA $79         ; Espers palette
         STA $29         ; Set attributes
         LDY #C35C48     ; Text pointer
         JSR C302F9      ; Draw "Espers"
         LDA $7A         ; Magic palette
         STA $29         ; Set attributes
         LDY #C35C51     ; Text pointer
         JSR C302F9      ; Draw "Magic"
         LDA $7B         ; SwdTech palette
         STA $29         ; Set attributes
         LDY #C35C59     ; Text pointer
         JSR C302F9      ; Draw "SwdTech"
         LDA $7C         ; Blitz palette
         STA $29         ; Set attributes
         LDY #C35C63     ; Text pointer
         JSR C302F9      ; Draw "Blitz"
         LDA $7D         ; Lore palette
         STA $29         ; Set attributes
         LDY #C35C6B     ; Text pointer
         JSR C302F9      ; Draw "Lore"
         LDA $7E         ; Rage palette
         STA $29         ; Set attributes
         LDY #C35C72     ; Text pointer
         JSR C302F9      ; Draw "Rage"
         LDA $7F         ; Dance palette
         STA $29         ; Set attributes
         LDY #C35C79     ; Text pointer
         JSR C302F9      ; Draw "Dance"
         JMP C30E6E      ; Upload BG3 A+B

; Draw actor info in Skills menu, including blue text
C34D27:  JSR C36A15      ; Clear BG1 map A
         JSR C36A19      ; Clear BG1 map B
         LDA #$24        ; Palette 1
         STA $29         ; Color: Blue
         LDX #C35C81     ; Text ptrs loc
         LDY #$0006      ; Strings: 3
         JSR C369BA      ; Draw "LV/HP/MP"
         JMP C34EE5      ; Draw actor info

; Assign a palette to each submenu in Skills menu
C34D3D:  LDA #$24        ; Gray palette
         LDX $00         ; 1st: Espers
C34D41:  STA $79,X       ; Disable menu
         INX             ; Menu slot +1
         CPX #$0007      ; Done Dance?
         BNE C34D41      ; Loop if not
         JSR C34EDD      ; Actor's address
         PHY             ; Memorize it
         LDX #$0004      ; Commands: 4
C34D50:  PHX             ; Save counter
         LDX $00         ; 1st: Espers
C34D53:  LDA $0016,Y     ; Actor's command
         CMP.L C34D78,X  ; Unlocks submenu?
         BNE C34D60      ; Skip menu if not
         LDA #$20        ; Color: User's
         STA $79,X       ; Enable menu
C34D60:  INX             ; Menu slot +1
         CPX #$0007      ; Done Dance?
         BNE C34D53      ; Loop if not
         INY             ; Cmd slot +1
         PLX             ; Loop counter
         DEX             ; One less cmd
         BNE C34D50      ; Loop till last
         PLY             ; Actor's address
         LDA $0000,Y     ; Actor
         CMP #$0C        ; Gogo?
         BNE C34D77      ; Exit if not
         LDA #$24        ; Gray palette
         STA $79         ; Disable Espers
C34D77:  RTS

; Battle commands that unlock a skill menu
C34D78:  db $02          ; Magic (unlocks Espers)
         db $02          ; Magic (unlocks Magic)
         db $07          ; SwdTech
         db $0A          ; Blitz
         db $0C          ; Lore
         db $10          ; Rage
         db $13          ; Dance

; Draw Magic list and blue "MP…" and create portrait
C34D7F:  JSR C36A15      ; Clear BG1 map A
         JSR C34F1C      ; Build spell list
         JSR C34F87      ; Draw spell list
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         LDY #C35C87     ; Text pointer
         JSR C302F9      ; Draw "MP…"
         JSR C361AC      ; Create portrait
         JMP C30F4D      ; Queue BG3 upload

; Window layout for main Skills menu
C34D98:  dw $588B,$0407  ; 09x06 at $588B (Upper submenus)
C34D9C:  dw $5A0B,$0A07  ; 09x12 at $5A0B (Lower submenus)
C34DA0:  dw $59CB,$051C  ; 30x07 at $59CB (Stats)
C34DA4:  dw $5B8B,$0C1C  ; 30x14 at $5B8B (Bottom)
C34DA8:  dw $588B,$031C  ; 30x05 at $588B (Top)

; Window layout for Skills submenus
C34DAC:  dw $61CB,$051C  ; 30x07 at $61CB (Stats)
C34DB0:  dw $638B,$0C1C  ; 30x14 at $638B (List)
C34DB4:  dw $6175,$0107  ; 09x03 at $6175 (Title)
C34DB8:  dw $608B,$031C  ; 30x05 at $608B (Description)

; Set to condense text in Skills menu or submenu
C34DBC:  LDA #$02        ; 1Rx2B to PPU
         STA $4350       ; Set CH5 mode
         LDA #$12        ; $2112
         STA $4351       ; To BG3 V-Scroll
         LDY #C34E26     ; C3/4E26
         STY $4352       ; Set CH5 src LBs
         LDA #$C3        ; Bank: C3
         STA $4354       ; Set CH5 src HB
         LDA #$C3        ; ...
         STA $4357       ; Set indir HB
         LDA #$20        ; Channel: 5
         TSB $43         ; Queue HDMA-5
         JSR C34E2D      ; Load BG1 V-Data
         LDX $00         ; Index: 0
C34DDF:  LDA.L C34E72,X  ; BG1 H-Pan data
         STA $7E9A09,X   ; Save in RAM
         INX             ; Index +1
         CPX #$000D      ; End of table?
         BNE C34DDF      ; Loop if not
         LDA #$02        ; 1Rx2B to PPU
         STA $4360       ; Set CH6 mode
         LDA #$0D        ; $210D
         STA $4361       ; To BG1 H-Scroll
         LDY #$9A09      ; 7E/9A09
         STY $4362       ; Set CH6 src LBs
         LDA #$7E        ; Bank: 7E
         STA $4364       ; Set CH6 src HB
         LDA #$7E        ; ...
         STA $4367       ; Set indir HB
         LDA #$02        ; 1Rx2B to PPU
         STA $4370       ; Set CH7 mode
         LDA #$0E        ; $210E
         STA $4371       ; To BG1 V-Scroll
         LDY #$9849      ; 7E/9849
         STY $4372       ; Set CH7 src LBs
         LDA #$7E        ; Bank: 7E
         STA $4374       ; Set CH7 src HB
         LDA #$7E        ; ...
         STA $4377       ; Set indir HB
         LDA #$C0        ; Channels: 6, 7
         TSB $43         ; Queue HDMA 6+7
         RTS

; BG3 vertical shift table for skill menus
C34E26:  db $4F,$02,$00  ; SwdTech and above
         db $40,$02,$00  ; Blitz and below
         db $00          ; End

; Load vertical shift values for BG1 text in skill menus
C34E2D:  LDX $00         ; Index: 0
C34E2F:  LDA.L C34E7F,X  ; Stats V-Data
         STA $7E9849,X   ; Save in RAM
         INX             ; Index +1
         CPX #$0012      ; At skills?
         BNE C34E2F      ; Loop if not
C34E3D:  LDA.L C34E7F,X  ; Skill V-Data
         STA $7E9849,X   ; Save in RAM
         INX             ; Index +1
         TDC             ; Clear A
         LDA $49         ; Top BG1 row
         ASL A           ; x2
         ASL A           ; x4
         ASL A           ; x8
         ASL A           ; x16
         AND #$FF        ; ...
         REP #$20        ; 16-bit A
         CLC             ; Prepare ADC
         ADC.L C34E7F,X  ; Add V-Data
         STA $7E9849,X   ; Save in RAM
         SEP #$20        ; 8-bit A
         INX             ; Index +1
         INX             ; Index +1
         CPX #$005A      ; Past list?
         BNE C34E3D      ; Loop if not
C34E63:  LDA.L C34E7F,X  ; Bottom V-Data
         STA $7E9849,X   ; Save in RAM
         INX             ; Index +1
         CPX #$005E      ; End of table?
         BNE C34E63      ; Loop if not
         RTS

; BG1 H-Shift table for skill menus (merges tilemaps)
C34E72:  db $27,$00,$01  ; Nothing
         db $48,$00,$01  ; Member stats
         db $60,$00,$00  ; Spells, etc.
         db $1E,$00,$01  ; Nothing
         db $00          ; End

; BG1 V-Shift table for skill menus (condenses text)
C34E7F:  db $3F,$00,$00  ; LV
         db $0C,$04,$00  ; HP
         db $0C,$08,$00  ; MP
         db $0A,$0C,$00  ; Nothing
         db $01,$0C,$00  ; Nothing
         db $0D,$08,$00  ; Nothing
         db $04,$94,$FF  ; Ability row A
         db $04,$94,$FF  ; Ability row B
         db $04,$94,$FF  ; Ability row C
         db $04,$98,$FF  ; Ability row D
         db $04,$98,$FF  ; Ability row E
         db $04,$98,$FF  ; Ability row F
         db $04,$9C,$FF  ; Ability row G
         db $04,$9C,$FF  ; Ability row H
         db $04,$9C,$FF  ; Ability row I
         db $04,$A0,$FF  ; Ability row J
         db $04,$A0,$FF  ; Ability row K
         db $04,$A0,$FF  ; Ability row L
         db $04,$A4,$FF  ; Ability row M
         db $04,$A4,$FF  ; Ability row N
         db $04,$A4,$FF  ; Ability row O
         db $04,$A8,$FF  ; Ability row P
         db $04,$A8,$FF  ; Ability row Q
         db $04,$A8,$FF  ; Ability row R
         db $04,$AC,$FF  ; Ability row S
         db $04,$AC,$FF  ; Ability row T
         db $04,$AC,$FF  ; Ability row U
         db $04,$B0,$FF  ; Ability row V
         db $04,$B0,$FF  ; Ability row W
         db $04,$B0,$FF  ; Ability row X
         db $1E,$20,$FF  ; Ability row Y
         db $00          ; End

; Load member's SRAM block address for Skills menu
C34EDD:  TDC             ; Clear A
         LDA $28         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         LDY $6D,X       ; SRAM address
         RTS

; Draw actor info in Skills menu
C34EE5:  JSR C34EDD      ; Actor's address
         STY $67         ; Memorize it
         JMP C34EED      ; ...
C34EED:  LDY #$42DD      ; Class/KO pos
         LDX #$4F50      ; Icon position
         JSR C33427      ; Display status
         LDY #C35CD1     ; Text pointer
         JSR C302F9      ; Draw HP's "/"
         LDY #C35CD5     ; Text pointer
         JSR C302F9      ; Draw MP's "/"
         LDX #C34F12     ; Coords tbl ptr
         JSR C30C6C      ; Draw LV, HP, MP
C34F08:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDY #$421D      ; Text position
         JMP C334E6      ; Draw held esper

; Tilemap pointers for stats in Skills menu
C34F12:  dw $4237        ; Level
         dw $42B3        ; HP
         dw $42BD        ; Max HP
         dw $4333        ; MP
         dw $433D        ; Max MP

; Build Magic list based on Mag.Order
C34F1C:  LDX #$9D89      ; 7E/9D89
         STX $2181       ; Set WRAM LBs
         LDX #$0036      ; Spells: 54
         LDA #$FF        ; Spell: None
C34F27:  STA $2180       ; Add to list
         DEX             ; One less spell
         BNE C34F27      ; Loop till last
         TDC             ; Clear A
         TAY             ; List slot: 1
         LDA $1D54       ; Game options
         AND #$07        ; Get Mag.Order
         ASL A           ; x2
         ASL A           ; x4
         TAX             ; Index it
C34F37:  PHX             ; Save index
         LDA.L C34F49,X  ; Starting spell
         CMP #$FF        ; At terminator?
         BEQ C34F47      ; Exit if so
         JSR C34F61      ; Populate list
         PLX             ; Type index
         INX             ; Index +1
         BRA C34F37      ; Do next type
C34F47:  PLX             ; Unstack index
         RTS

; Starting spell for each Magic type, sorted based on Mag.Order
C34F49:  db $2D,$00,$18,$FF  ; 1: Cure, Fire, Scan
         db $2D,$18,$00,$FF  ; 2: Cure, Scan, Fire
         db $00,$18,$2D,$FF  ; 3: Fire, Scan, Cure
         db $00,$2D,$18,$FF  ; 4: Fire, Cure, Scan
         db $18,$2D,$00,$FF  ; 5: Scan, Cure, Fire
         db $18,$00,$2D,$FF  ; 6: Scan, Fire, Cure

; Add spells of given type to Magic list based on starting spell
C34F61:  CMP #$00        ; Fire?
         BEQ C34F6E      ; Branch if so
         CMP #$2D        ; Cure?
         BEQ C34F73      ; Branch if so
         LDX #$0015      ; Spells: 21
         BRA C34F78      ; Build list

; Fork: Black magic
C34F6E:  LDX #$0018      ; Spells: 24
         BRA C34F78      ; Build list

; Fork: White magic
C34F73:  LDX #$0009      ; Spells: 9
         BRA C34F78      ; ...

; Fork: Populate list
C34F78:  STX $E0         ; Set spells left
         TAX             ; ...
C34F7B:  TYX             ; List slot
         STA $7E9D89,X   ; Add spell there
         INC A           ; Spell number +1
         INY             ; List slot +1
         DEC $E0         ; One less spell
         BNE C34F7B      ; Loop till last
         RTS

; Draw Magic list
C34F87:  JSR C383F7      ; Define $E5, $E6
         LDY #$0008      ; Rows left: 8
C34F8D:  PHY             ; Save counter
         JSR C34F9E      ; Draw 2 spells
         LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         INC A           ; Go 1 row down
         AND #$1F        ; Stay in limits
         STA $E6         ; Save changes
         PLY             ; Rows left
         DEY             ; One less left
         BNE C34F8D      ; Loop till last
         RTS

; Draw a row of two spells in Magic menu
C34F9E:  JSR C34FB5      ; Define source
         LDX #$0003      ; X: 3
         JSR C34FC4      ; Draw spell A
         INC $E5         ; Menu slot +1
         JSR C34FB5      ; Define source
         LDX #$0010      ; X: 16
         JSR C34FC4      ; Draw spell B
         INC $E5         ; Menu slot +1
         RTS

; Set source for loading Magic name
C34FB5:  LDY #$0007      ; Letters: 7
         STY $EB         ; Set src size
         LDY #$F567      ; E6/F567
         STY $EF         ; Set src LBs
         LDA #$E6        ; Bank: E6
         STA $F1         ; Set src HB
         RTS

; Draw text in spell slot of Magic menu
C34FC4:  LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         JSR C3809F      ; Compute map ptr
         REP #$20        ; 16-bit A
         TXA             ; ...
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         LDA $9E         ; Show MP in list?
         BEQ C3503E      ; Branch if not
         JSR C350EC      ; Spell
         JSR C3514D      ; Handle graying
         JSR C350EC      ; Spell
         CMP #$FF        ; None?
         BEQ C3501A      ; Blank if so
         JSR C350A2      ; Spell mastery
         CMP #$FF        ; Fully learned?
         BNE C3501A      ; Blank if not

; Fork: Draw spell plus MP cost
C34FEB:  JSR C350EC      ; Spell
         JSR C38467      ; Load name
         LDX #$9E92      ; 7E/9E92
         STX $2181       ; Set WRAM LBs
         LDA #$FF        ; Space char
         STA $2180       ; Add to string
         JSR C350EC      ; Spell
         JSR C3510D      ; Define MP cost
         JSR C304E0      ; Turn into text
         LDA $F8         ; Tens digit
         STA $2180       ; Add to string
         LDA $F9         ; Ones digit
         STA $2180       ; Add to string
         LDA #$FF        ; Space char
         STA $2180       ; Add to string
         STZ $2180       ; End string
         JMP C37FD9      ; Draw string

; Fork: Blank spell slot
C3501A:  TDC             ; Clear A
         LDA $E5         ; Spell slot
         TAX             ; Index it
         LDA #$FF        ; Spell: None
         STA $7E9D89,X   ; Assign to slot
         JSR C351B9      ; Disable spell
         LDY #$000B      ; Letters: 11
         LDX #$9E8B      ; 7E/9E8B
         STX $2181       ; Set WRAM LBs
         LDA #$FF        ; Space char
C35032:  STA $2180       ; Add to string
         DEY             ; One less left
         BNE C35032      ; Loop till last
         STZ $2180       ; End string
         JMP C37FD9      ; Draw 11 spaces

; Fork: Draw spell plus percentage
C3503E:  JSR C350EC      ; Spell
         CMP #$FF        ; None?
         BEQ C3501A      ; Blank if so
         JSR C350A2      ; Spell mastery
         CMP #$00        ; Zero?
         BEQ C3501A      ; Blank if so
         JSR C350EC      ; Spell
         JSR C38467      ; Load name
         LDX #$9E92      ; 7E/9E92
         STX $2181       ; Set WRAM LBs
         JSR C350EC      ; Spell
         JSR C350A2      ; Spell mastery
         CMP #$FF        ; Fully learned?
         BEQ C35088      ; Branch if so
         PHA             ; Save mastery
         JSR C351B9      ; Disable spell
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Bluish
         LDA.B #!3dot    ; Char: "…"
         STA $2180       ; Add to string
         PLA             ; Spell mastery
         JSR C304E0      ; Turn into text
         LDA $F8         ; Tens digit
         STA $2180       ; Add to string
         LDA $F9         ; Ones digit
         STA $2180       ; Add to string
         LDA.B #!perc    ; Char: "%"
         STA $2180       ; Add to string
C35082:  STZ $2180       ; End string
         JMP C37FD9      ; Draw string

; Fork: Draw spell name only
C35088:  LDA #$24        ; Palette 1
         STA $29         ; Color: Blue...
         JSR C350EC      ; Spell
         JSR C3514D      ; Handle graying
         LDA #$FF        ; Space char
         STA $2180       ; Add to string
         STA $2180       ; Add to string
         STA $2180       ; Add to string
         STA $2180       ; Add to string
         BRA C35082      ; Draw string

; Get spell's mastery percentage
C350A2:  STA $E0         ; Save spell
         JSR C34EDD      ; Define Y
         LDA $0000,Y     ; Actor
         CMP #$0C        ; Gogo?
         BEQ C350C5      ; Branch if so
C350AE:  STA $4202       ; Set multiplicand
         LDA #$36        ; Spell list size
         STA $4203       ; Set multiplier
         TDC             ; Clear A
         LDA $E0         ; Spell
         REP #$20        ; 16-bit A
         ADC $4216       ; Add product
         TAX             ; Index sum
         SEP #$20        ; 8-bit A
         LDA $1A6E,X     ; Spell mastery
         RTS

; Fork: Test all members for Gogo
C350C5:  STZ $E1         ; Member slot: 1
C350C7:  TDC             ; ...
         LDA $E1         ; Tested member
         CMP $28         ; Gogo?
         BEQ C350E2      ; Skip if so
         ASL A           ; Double it
         TAX             ; Index it
         LDY $6D,X       ; Actor's address
         BEQ C350E2      ; Skip if nobody
         LDA $0000,Y     ; Actor in slot
         CMP #$0C        ; Gogo or higher?
         BCS C350E2      ; Skip if so
         JSR C350AE      ; Actor's mastery
         CMP #$FF        ; Fully learned?
         BEQ C350EB      ; Exit if so
C350E2:  INC $E1         ; Member slot +1
         LDA $E1         ; Members done
         CMP #$04        ; Done all 4?
         BNE C350C7      ; Loop if not
         TDC             ; Mastery: 0
C350EB:  RTS

; Get processed spell
C350EC:  TDC             ; Clear A
         LDA $E5         ; Spell slot
         TAX             ; Index it
         LDA $7E9D89,X   ; Spell in slot
         RTS

; Compute spell data index
C350F5:  PHA             ; Save spell
C350F6:  LDA $4212       ; PPU status
         AND #$40        ; H-Blank?
         BEQ C350F6      ; Loop if not
         PLA             ; Spell
         STA $211B       ; Set matrix A LB
         STZ $211B       ; Clear HB
         LDA #$0E        ; Data size
         STA $211C       ; Set matrix B
         STA $211C       ; ...
         RTS

; Define spell's MP cost
C3510D:  PHA             ; Save spell
         JSR C350F5      ; Compute index
         LDX $2134       ; Load it
         LDA $C46AC5,X   ; Base MP cost
         STA $E0         ; Memorize it

; Fork: Step Mine
C3511A:  PLA             ; Spell
         CMP #$99        ; Step Mine?
         BNE C3512E      ; Branch if not
         LDA $021B       ; Hours played
         ASL A           ; Double them
         STA $E0         ; Set MP cost
         LDA $021C       ; Minutes played
         CMP #$1E        ; Under 30?
         BCC C3512E      ; Branch if so
         INC $E0         ; MP cost +1

; Fork: Economizer
C3512E:  LDA $11D7       ; Gear effects
         BIT #$40        ; Economizer's?
         BEQ C3513A      ; Branch if not
         TDC             ; Clear A
         LDA #$01        ; MP cost: 1
         BRA C3514B      ; Put it in X

; Fork: Gold Hairpin
C3513A:  LDA $11D7       ; Gear effects
         BIT #$20        ; Gold Hairpin?
         BEQ C35148      ; Branch if not
         TDC             ; Clear A
         LDA $E0         ; MP cost
         INC A           ; Add one
         LSR A           ; Halve it
         BRA C3514B      ; Put it in X

; Fork: Normal MP cost
C35148:  TDC             ; Clear A
         LDA $E0         ; Base MP cost
C3514B:  TAX             ; Put it in X
         RTS

; Enable or disable spell in Magic menu
C3514D:  CMP #$2A        ; Warp?
         BEQ C3517B      ; Branch if so
         CMP #$12        ; X-Zone?
         BEQ C3516E      ; Branch if so
C35155:  JSR C350F5      ; Compute index
         LDX $2134       ; Load it
         LDA $C46AC3,X   ; Spell properties
         AND #$01        ; Usable in field?
         BEQ C3516C      ; Disable if not
         JSR C350EC      ; Spell
         JSR C3510D      ; Define MP cost
         JMP C35188      ; Test MP and Imp

; Fork: Disable spell
C3516C:  BRA C351B9      ; Go directly...

; Fork: X-Zone (unused feature)
C3516E:  STA $E3         ; Memorize spell
         LDA $0201       ; Area permissions
         BIT #$01        ; Forbid X-Zone?
         BEQ C3516C      ; Disable if so
         LDA $E3         ; Spell number
         BRA C35155      ; Do basic checks

; Fork: Warp
C3517B:  STA $E3         ; Memorize spell
         LDA $0201       ; Area permissions
         BIT #$02        ; Can warp here?
         BEQ C3516C      ; Disable if not
         LDA $E3         ; Spell number
         BRA C35155      ; Do basic checks

; Fork: Test Imp
C35188:  STX $E2         ; Save MP cost
         JSR C34EDD      ; Define Y
         LDA $0014,Y     ; Actor's status
         AND #$20        ; Imp?
         BEQ C3519B      ; Branch if not
         JSR C350EC      ; Spell
         CMP #$23        ; Imp?
         BNE C351B9      ; Disable if not

; Fork: Test MP
C3519B:  REP #$20        ; 16-bit A
         LDA $000D,Y     ; Actor's MP
         STA $E0         ; Memorize it
         SEP #$20        ; 8-bit A
         LDX $E2         ; MP cost
         CPX $E0         ; Equals user MP?
         BEQ C351AC      ; Enable if so
         BCS C351B9      ; Block if above

; Fork: Enable spell
C351AC:  TDC             ; Clear A
         LDA $E5         ; Spell slot
         TAX             ; Index it
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         STA $7E9E09,X   ; Enable spell
         RTS

; Fork: Disable spell
C351B9:  TDC             ; Clear A
         LDA $E5         ; Spell slot
         TAX             ; Index it
         LDA #$28        ; Palette 2
         STA $29         ; Color: Gray
         STA $7E9E09,X   ; Disable spell
         RTS

; Draw MP cost in corner of Magic menu
C351C6:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         REP #$20        ; 16-bit A
         LDA #$81BF      ; Tilemap ptr
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         LDX #$9E8B      ; 7E/9E8B
         STX $2181       ; Set WRAM LBs
         TDC             ; Clear A
         LDA $4B         ; List slot
         TAX             ; Index it
         LDA $7E9D89,X   ; Spell in slot
         JSR C3510D      ; Define MP cost
         JSR C304E0      ; Turn into text
         LDA $F8         ; Tens digit
         STA $2180       ; Add to string
         LDA $F9         ; Ones digit
         STA $2180       ; Add to string
         STZ $2180       ; End string
         JMP C37FD9      ; Draw MP cost

; Draw Lore list and menu title, create portrait
C351F9:  JSR C36A15      ; Clear BG1 map A
         JSR C3523C      ; Draw Lore list
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         LDY #C35C91     ; Text pointer
         JSR C302F9      ; Draw "Lore"
         JSR C361AC      ; Create portrait
         JMP C30F4D      ; Queue BG3 upload

; Build Lore list
C3520F:  LDX #$9D89      ; 7E/9D89
         STX $2181       ; Set WRAM LBs
         LDX $00         ; Index: 0
         STZ $E0         ; 1st: Condemned
C35219:  LDY #$0008      ; Lores left: 8
         LDA $1D29,X     ; 8 known lores
C3521F:  ROR A           ; Got current?
         PHA             ; Save 8 lores
         BCC C3522A      ; Blank if not
         LDA $E0         ; Lore number
         STA $2180       ; Add to list
         BRA C3522F      ; Skip 2 lines
C3522A:  LDA #$FF        ; Esper: None
         STA $2180       ; Add to list
C3522F:  INC $E0         ; Lore number +1
         PLA             ; 8 known lores
         DEY             ; Lores left -1
         BNE C3521F      ; Loop till last
         INX             ; Point to next 8
         CPX #$0003      ; Done 24 lores?
         BNE C35219      ; Loop if not
         RTS

; Build and draw Lore list
C3523C:  JSR C3520F      ; Build Lore list
         JSR C383F7      ; Define $E5, $E6
         LDY #$0008      ; Lores left: 8
C35245:  PHY             ; Save counter
         JSR C35256      ; Draw name, cost
         LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         INC A           ; Go 1 row down
         AND #$1F        ; Stay in limits
         STA $E6         ; Save changes
         PLY             ; Lores left
         DEY             ; One less left
         BNE C35245      ; Loop till last
         RTS

; Prepare to and draw Lore's name and MP cost
C35256:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         JSR C35266      ; Define source
         LDX #$0003      ; X: 3
         JSR C35275      ; Draw string
         INC $E5         ; Lore slot +1
         RTS

; Set source for loading Lore name
C35266:  LDY #$000A      ; Letters: 10
         STY $EB         ; Set src size
         LDY #$F9FD      ; E6/F9FD
         STY $EF         ; Set src LBs
         LDA #$E6        ; Bank: E6
         STA $F1         ; Set src HB
         RTS

; Draw Lore's name and MP cost
C35275:  LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         JSR C3809F      ; Compute map ptr
         REP #$20        ; 16-bit A
         TXA             ; ...
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $E5         ; Lore slot
         TAX             ; Index it
         LDA $7E9D89,X   ; Lore in slot
         CMP #$FF        ; None?
         BEQ C352C0      ; Blank if so
         LDA $E5         ; Lore slot
         JSR C38467      ; Load name
         LDX #$9E95      ; 7E/9E95
         STX $2181       ; Set WRAM LBs
         LDA.B #!3dot    ; Char: "…"
         STA $2180       ; Add to string
         LDA $E5         ; Lore slot
         CLC             ; Prepare ADC
         ADC #$8B        ; Get attack ID
         JSR C3510D      ; Define MP cost
         JSR C304E0      ; Turn into text
         LDA $F7         ; Hundreds digit
         STA $2180       ; Add to string
         LDA $F8         ; Tens digit
         STA $2180       ; Add to string
         LDA $F9         ; Ones digit
         STA $2180       ; Add to string
         STZ $2180       ; End string
         JMP C37FD9      ; Draw string

; Fork: Blank Lore slot
C352C0:  LDY #$000E      ; Letters: 14
         LDX #$9E8B      ; 7E/9E8B
         STX $2181       ; Set WRAM LBs
         LDA #$FF        ; Space char
C352CB:  STA $2180       ; Add to string
         DEY             ; One less left
         BNE C352CB      ; Loop till last
         STZ $2180       ; End string
         JMP C37FD9      ; Draw 14 spaces

; Draw SwdTech list and menu title, create portrait
C352D7:  JSR C36A15      ; Clear BG1 map A
         JSR C3536E      ; Build tech list
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         JSR C352F4      ; Draw tech list
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         LDY #C35CB8     ; Text pointer
         JSR C302F9      ; Draw "SwdTech"
         JSR C361AC      ; Create portrait
         JMP C30F4D      ; Queue BG3 upload

; Draw SwdTech list
C352F4:  JSR C383F7      ; Define $E5, $E6
         INC $E6         ; BG1 write row +1
         STZ $E5         ; Tech slot: 1
         LDY #$0004      ; Rows left: 4
C352FE:  PHY             ; Save counter
         JSR C35311      ; Draw 2 names
         LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         INC A           ; Go 1 row down
         INC A           ; Go 1 row down
         INC A           ; Go 1 row down
         AND #$1F        ; Stay in limits
         STA $E6         ; Save changes
         PLY             ; Rows left
         DEY             ; One less left
         BNE C352FE      ; Loop till last
         RTS

; Draw a row of two SwdTechs
C35311:  JSR C35328      ; Define source
         LDX #$0003      ; X: 3
         JSR C35337      ; Draw tech A
         INC $E5         ; Tech slot +1
         JSR C35328      ; Define source
         LDX #$0011      ; X: 17
         JSR C35337      ; Draw tech B
         INC $E5         ; Tech slot +1
         RTS

; Set source for loading SwdTech name
C35328:  LDY #$000C      ; Letters: 12
         STY $EB         ; Set src size
         LDY #$3C40      ; CF/3C40
         STY $EF         ; Set src LBs
         LDA #$CF        ; Bank: CF
         STA $F1         ; Set src HB
         RTS

; Draw SwdTech name
C35337:  LDA $E6         ; BG1 write row
         JSR C3809F      ; Compute map ptr
         REP #$20        ; 16-bit A
         TXA             ; ...
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $E5         ; Tech slot
         TAX             ; Index it
         LDA $7E9D89,X   ; Tech in slot
         CMP #$FF        ; None?
         BEQ C35357      ; Blank if so
         JSR C38467      ; Load name
         JMP C37FD9      ; Draw name

; Fork: Blank SwdTech slot
C35357:  LDY #$000C      ; Spaces: 12
         LDX #$9E8B      ; 7E/9E8B
         STX $2181       ; Set WRAM LBs
         LDA #$FF        ; Space char
C35362:  STA $2180       ; Add to string
         DEY             ; One less left
         BNE C35362      ; Loop till last
         STZ $2180       ; End string
         JMP C37FD9      ; Draw 12 spaces

; Build SwdTech list
C3536E:  LDX #$9D89      ; 7E/9D89
         STX $2181       ; Set WRAM LBs
         LDY #$0008      ; Techs left: 8
         STZ $E0         ; 1st: Dispatch
         TDC             ; ...
         LDA $1CF7       ; 8 known techs
C3537D:  ROR A           ; Got current?
         PHA             ; Save 8 techs
         BCC C35385      ; Blank if not
         LDA $E0         ; SwdTech number
         BRA C35387      ; Skip a line
C35385:  LDA #$FF        ; SwdTech: None
C35387:  STA $2180       ; Add to list
         INC $E0         ; Tech number +1
         PLA             ; 8 known techs
         DEY             ; Techs left -1
         BNE C3537D      ; Loop till last
         RTS

; Draw Rage list and menu title, create portrait
C35391:  JSR C36A15      ; Clear BG1 map A
         JSR C353A7      ; Draw Rage list
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         LDY #C35C98     ; Text pointer
         JSR C302F9      ; Draw "Rage"
         JSR C361AC      ; Create portrait
         JMP C30F4D      ; Queue BG3 upload

; Build and draw Rage list
C353A7:  JSR C353C1      ; Build Rage list
         JSR C383F7      ; Define $E5, $E6
         LDY #$0009      ; Rows left: 9...
C353B0:  PHY             ; Save counter
         JSR C353EE      ; Draw 2 Rages
         LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         INC A           ; Go 1 row down
         AND #$1F        ; Stay in limits
         STA $E6         ; Save changes
         PLY             ; Rows left
         DEY             ; One less left
         BNE C353B0      ; Loop till last
         RTS

; Build Rage list
C353C1:  LDX #$9D89      ; 7E/9D89
         STX $2181       ; Set WRAM LBs
         LDX $00         ; Pack index: 0
         STZ $E0         ; Current: Guard
C353CB:  LDY #$0008      ; Rages left: 8
         LDA $1D2C,X     ; 8 known Rages
C353D1:  ROR A           ; Got current?
         PHA             ; Save 8 Rages
         BCC C353DC      ; Blank if not
         LDA $E0         ; Rage number
         STA $2180       ; Add to list
         BRA C353E1      ; Skip 2 lines
C353DC:  LDA #$FF        ; Rage: None
         STA $2180       ; Add to list
C353E1:  INC $E0         ; Rage number +1
         PLA             ; 8 known Rages
         DEY             ; Rages left -1
         BNE C353D1      ; Loop till last
         INX             ; Point to next 8
         CPX #$0020      ; Done 256 Rages?
         BNE C353CB      ; Loop if not
         RTS

; Draw a row of two Rages
C353EE:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         JSR C35409      ; Define source
         LDX #$0005      ; X: 5
         JSR C35418      ; Draw Rage A
         INC $E5         ; Rage slot +1
         JSR C35409      ; Define source
         LDX #$0013      ; X: 19
         JSR C35418      ; Draw Rage B
         INC $E5         ; Rage slot +1
         RTS

; Set source for loading enemy name
C35409:  LDY #$000A      ; Letters: 10
         STY $EB         ; Set src size
         LDY #$C050      ; CF/C050
         STY $EF         ; Set src LBs
         LDA #$CF        ; Bank: CF
         STA $F1         ; Set src HB
         RTS

; Draw Rage name
C35418:  LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         JSR C3809F      ; Compute map ptr
         REP #$20        ; 16-bit A
         TXA             ; ...
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $E5         ; Rage slot
         TAX             ; Index it
         LDA $7E9D89,X   ; Rage in slot
         CMP #$FF        ; None or Pugs?
         BEQ C3543B      ; Blank if so
         LDA $E5         ; Rage slot
         JSR C38467      ; Load name
         JMP C37FD9      ; Draw name

; Fork: Blank Rage slot
C3543B:  LDY #$000A      ; Spaces: 10
         LDX #$9E8B      ; 7E/9E8B
         STX $2181       ; Set WRAM LBs
         LDA #$FF        ; Space char
C35446:  STA $2180       ; Add to string
         DEY             ; One less left
         BNE C35446      ; Loop till last
         STZ $2180       ; End string
         JMP C37FD9      ; Draw 10 spaces

; Draw esper list and menu title, create portrait
C35452:  JSR C36A15      ; Clear BG1 map A
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         JSR C3546C      ; Draw esper list
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         LDY #C35CA7     ; Text pointer
         JSR C302F9      ; Draw "Espers"
         JSR C361AC      ; Create portrait
         JMP C30F4D      ; Queue BG3 upload

; Build and draw esper list
C3546C:  JSR C35486      ; Build esper list
         JSR C383F7      ; Define $E5, $E6
         LDY #$0008      ; Rows left: 8
C35475:  PHY             ; Save counter
         JSR C354E3      ; Draw 2 espers
         LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         INC A           ; Go 1 row down
         AND #$1F        ; Stay in limits
         STA $E6         ; Save changes
         PLY             ; Rows left
         DEY             ; One less left
         BNE C35475      ; Loop till last
         RTS

; Build sorted esper list
C35486:  LDX #$9DED      ; 7E/9DED
         STX $2181       ; Set WRAM LBs
         LDX $00         ; Pack index: 0
         STZ $E0         ; Current: Ramuh
C35490:  LDY #$0008      ; Espers left: 8
         LDA $1A69,X     ; 8 owned espers
C35496:  ROR A           ; Got current?
         PHA             ; Save 8 espers
         BCC C354A1      ; Blank if not
         LDA $E0         ; Esper number
         STA $2180       ; Add to list
         BRA C354A6      ; Skip 2 lines
C354A1:  LDA #$FF        ; Esper: None
         STA $2180       ; Add to list
C354A6:  INC $E0         ; Esper number +1
         PLA             ; 8 owned espers
         DEY             ; Espers left -1
         BNE C35496      ; Loop till last
         INX             ; Point to next 8
         CPX #$0004      ; Done 32 espers?
         BNE C35490      ; Loop if not

; Fork: Clear sorted list
C354B2:  LDX #$9D89      ; 7E/9D89
         STX $2181       ; Set WRAM LBs
         LDA #$FF        ; Esper: None
         LDX #$001D      ; Slots left: 29
C354BD:  STA $2180       ; Clear list slot
         DEX             ; One less left
         BNE C354BD      ; Loop till last

; Fork: Build sorted list
C354C3:  LDX #$9DED      ; 7E/9DED
         STX $2181       ; Set WRAM LBs
         LDY #$001B      ; Slots left: 27
         TDC             ; Clear A
C354CD:  LDA $2180       ; Esper in slot
         BMI C354DF      ; Skip if none
         PHA             ; Memorize it
         TAX             ; Index it
         LDA $D1F9B5,X   ; Intended slot
         DEC A           ; Subtract 1
         TAX             ; Index it
         PLA             ; Esper number
         STA $7E9D89,X   ; Add to new list
C354DF:  DEY             ; One less esper
         BNE C354CD      ; Loop till last
         RTS

; Draw a row of two esper names with MP cost
C354E3:  JSR C354FA      ; Define source
         LDX #$0003      ; X: 3
         JSR C35509      ; Draw esper A
         INC $E5         ; Esper slot +1
         JSR C354FA      ; Define source
         LDX #$0011      ; X: 17
         JSR C35509      ; Draw esper B
         INC $E5         ; Esper slot +1
         RTS

; Set source for loading esper name
C354FA:  LDY #$0008      ; Letters: 8
         STY $EB         ; Set src size
         LDY #$F6E1      ; E6/F6E1
         STY $EF         ; Set src LBs
         LDA #$E6        ; Bank: E6
         STA $F1         ; Set src HB
         RTS

; Draw esper's name and MP cost
C35509:  LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         JSR C3809F      ; Compute map ptr
         REP #$20        ; 16-bit A
         TXA             ; ...
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $E5         ; Esper slot
         TAX             ; Index it
         LDA $7E9D89,X   ; Esper in slot
         CMP #$FF        ; None?
         BEQ C3555D      ; Blank if so
         JSR C35574      ; Choose palette
         JSR C38467      ; Load name
         TDC             ; ...
         LDA $E5         ; Esper slot
         TAX             ; Index it
         LDA $7E9D89,X   ; Esper in slot
         CLC             ; Prepare ADC
         ADC #$36        ; Get attack ID
         JSR C3510D      ; Define MP cost
         PHA             ; Memorize it
         LDX #$9E93      ; 7E/9E93
         STX $2181       ; Set WRAM LBs
         LDA.B #!3dot    ; Char: "…"
         STA $2180       ; Add to string
         PLA             ; MP cost
         JSR C304E0      ; Turn into text
         LDA $F7         ; Hundreds digit
         STA $2180       ; Add to string
         LDA $F8         ; Tens digit
         STA $2180       ; Add to string
         LDA $F9         ; Ones digit
         STA $2180       ; Add to string
         STZ $2180       ; End string
         JMP C37FD9      ; Draw string

; Fork: Blank esper slot
C3555D:  LDY #$000C      ; Spaces: 12
         LDX #$9E8B      ; 7E/9E8B
         STX $2181       ; Set WRAM LBs
         LDA #$FF        ; Space char
C35568:  STA $2180       ; Add to string
         DEY             ; One less left
         BNE C35568      ; Loop till last
         STZ $2180       ; End string
         JMP C37FD9      ; Draw 12 spaces

; Define esper name color
C35574:  STA $E0         ; Save esper
         LDX $00         ; 1st: Terra
         LDY #$0010      ; Actors: 16
C3557B:  LDA $161E,X     ; Actor's esper
         CMP $E0         ; Matches ours?
         BEQ C35593      ; Gray out if so
         REP #$20        ; 16-bit A
         TXA             ; Actor address
         CLC             ; Prepare ADC
         ADC #$0025      ; Actor slot +1
         TAX             ; Reindex it
         SEP #$20        ; 8-bit A
         DEY             ; One less actor
         BNE C3557B      ; Loop till last
         LDA #$20        ; Color: User's
         BRA C35595      ; Skip a line
C35593:  LDA #$28        ; Color: Gray
C35595:  STA $29         ; Set palette
         LDA $E0         ; Esper to draw
         RTS

; Draw "<actor> has it!" in esper data menu
C3559A:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         REP #$20        ; 16-bit A
         LDA #$40CD      ; Tilemap ptr
         STA $7E9E89     ; Set position
         LDA #$9E8B      ; 7E/9E8B
         STA $2181       ; Set WRAM LBs
         SEP #$20        ; 8-bit A
         LDY #$0006      ; Letters: 6
C355B2:  LDA $1602,X     ; Name letter
         CMP #$FF        ; Terminator?
         BEQ C355C0      ; Done if so
         STA $2180       ; Add to string
         INX             ; Point to next
         DEY             ; One less left
         BNE C355B2      ; Loop till last
C355C0:  LDX $00         ; Letter: 1st
C355C2:  LDA.L C35CD9,X  ; Message letter
         BEQ C355CE      ; Done if end
         STA $2180       ; Add to string
         INX             ; Point to next
         BRA C355C2      ; Do next letter
C355CE:  STZ $2180       ; End string
         JMP C37FD9      ; Draw message

; Draw Blitz inputs and menu title, create portrait
C355D4:  JSR C36A15      ; Clear BG1 map A
         JSR C355EA      ; Draw inputs
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         LDY #C35CB0     ; Text pointer
         JSR C302F9      ; Draw "Blitz"
         JSR C361AC      ; Create portrait
         JMP C30F4D      ; Queue BG3 upload

; Build Blitz list and draw Blitz inputs
C355EA:  JSR C3561B      ; Build Blitz list
         JSR C383F7      ; Define $E5, $E6
         STZ $E5         ; Blitz slot: 1
         INC $E6         ; BG1 write row +1
         LDY #$0004      ; Rows left: 4
C355F7:  PHY             ; Save counter
         JSR C3560A      ; Draw inputs x2
         LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         INC A           ; Go 1 row down
         INC A           ; Go 1 row down
         INC A           ; Go 1 row down
         AND #$1F        ; Stay in limits
         STA $E6         ; Save changes
         PLY             ; Rows left
         DEY             ; One less left
         BNE C355F7      ; Loop till last
         RTS

; Draw a row of two sets of Blitz inputs
C3560A:  LDX #$0004      ; X: 4
         JSR C35643      ; Draw inputs A
         INC $E5         ; Blitz slot +1
         LDX #$0012      ; X: 18
         JSR C35643      ; Draw inputs B
         INC $E5         ; Blitz slot +1
         RTS

; Build Blitz list
C3561B:  LDA $1D28       ; Known Blitzes
         BRA C35623      ; Run Dance code

; Build Dance list
C35620:  LDA $1D4C       ; Known Dances
C35623:  LDX #$9D89      ; 7E/9D89
         STX $2181       ; Set WRAM LBs
         LDX $00         ; 1st: Wind Song
         LDY #$0008      ; Dances left: 8
C3562E:  ROR A           ; Know current?
         PHA             ; Save 8 Dances
         BCC C35638      ; Blank if not
         TXA             ; Dance number
         STA $2180       ; Add to list
         BRA C3563D      ; Skip 2 lines
C35638:  LDA #$FF        ; Dance: None
         STA $2180       ; Add to list
C3563D:  INX             ; Dance number +1
         PLA             ; Known Dances
         DEY             ; One less Dance
         BNE C3562E      ; Loop till last
         RTS

; Draw Blitz's inputs
C35643:  LDA $E6         ; BG1 write row
         JSR C3809F      ; Compute map ptr
         REP #$20        ; 16-bit A
         TXA             ; ...
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $E5         ; Blitz slot
         TAX             ; Index it
         LDA $7E9D89,X   ; Blitz in slot
         CMP #$FF        ; None?
         BEQ C3566C      ; Blank if so
         JSR C35683      ; Build tilemap
         LDY #$9E89      ; 7E/9E89
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         JMP C356BC      ; Move tilemap

; Fork: Blank Blitz slot
C3566C:  LDY #$0008      ; Spaces: 8
         LDX #$9E8B      ; 7E/9E8B
         STX $2181       ; Set WRAM LBs
         LDA #$FF        ; Space char
C35677:  STA $2180       ; Add to string
         DEY             ; One less left
         BNE C35677      ; Loop till last
         STZ $2180       ; End string
         JMP C37FD9      ; Draw 8 spaces

; Build tilemap for Blitz's inputs
C35683:  PHA             ; Save Blitz
         ASL A           ; x2
         ASL A           ; x4
         ASL A           ; x8
         STA $E0         ; Memorize it
         PLA             ; Blitz
         ASL A           ; x2
         ASL A           ; x4
         CLC             ; ...
         ADC $E0         ; x12
         TAX             ; Index it
         LDY #$9E8B      ; 7E/9E8B
         STY $2181       ; Set WRAM LBs
         LDY #$000A      ; Inputs: 10
C35699:  PHX             ; Save index
         LDA $C47A40,X   ; Blitz input
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C35C1C,X  ; Tile number
         STA $2180       ; Save in WRAM
         INX             ; Index +1
         LDA.L C35C1C,X  ; Attributes
         STA $2180       ; Save in WRAM
         INX             ; ...
         PLX             ; Input index
         INX             ; Input index +1
         DEY             ; One less input
         BNE C35699      ; Loop till last
         STZ $2180       ; End string LB
         STZ $2180       ; End string HB
         RTS

; Apply tilemap for Blitz's inputs
C356BC:  LDY $00         ; Index: 0
         REP #$20        ; 16-bit A
         LDA [$E7]       ; Tilemap ptr
         STA $EB         ; Set dest LBs
         INC $E7         ; Source +1
         INC $E7         ; Source +1
         SEP #$20        ; 8-bit A
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set dest HB
C356CE:  REP #$20        ; 16-bit A
         LDA [$E7],Y     ; Tile data
         BEQ C356DC      ; Exit if end
         STA [$EB],Y     ; Add to map
         SEP #$20        ; 8-bit A
         INY             ; Index +1
         INY             ; Index +1
         BRA C356CE      ; Do next tile
C356DC:  SEP #$20        ; 8-bit A
         RTS

; Load esper description
C356DF:  JSR C35C09      ; Load pointers
         JMP C3572A      ; Load description

; Load Magic description
C356E5:  JSR C35BE3      ; Load pointers
         JMP C3572A      ; Load description

; Load Lore description
C356EB:  LDX #$7A70      ; ED/7A70
         STX $E7         ; Set ptr loc LBs
         LDX #$77A0      ; ED/77A0
         STX $EB         ; Set text loc LBs
         LDA #$ED        ; Bank: ED
         STA $E9         ; Set ptr loc HB
         LDA #$ED        ; ...
         STA $ED         ; Set text loc HB
         JMP C3572A      ; Load description

; Load SwdTech description
C35700:  LDX #$FFAE      ; CF/FFAE
         STX $E7         ; Set ptr loc LBs
         LDX #$FD00      ; CF/FD00
         STX $EB         ; Set text loc LBs
         LDA #$CF        ; Bank: CF
         STA $E9         ; Set ptr loc HB
         LDA #$CF        ; ...
         STA $ED         ; Set text loc HB
         JMP C3572A      ; Load description

; Load Blitz description
C35715:  LDX #$FF9E      ; CF/FF9E
         STX $E7         ; Set ptr loc LBs
         LDX #$FC00      ; CF/FC00
         STX $EB         ; Set text loc LBs
         LDA #$CF        ; Bank: CF
         STA $E9         ; Set ptr loc HB
         LDA #$CF        ; ...
         STA $ED         ; Set text loc HB
         JMP C3572A      ; ...

; Load skill or item description
C3572A:  LDX #$9EC9      ; 7E/9EC9
         STX $2181       ; Set WRAM LBs
         TDC             ; Clear A
         LDA $4B         ; List slot
         TAX             ; Index it
         LDA $7E9D89,X   ; Skill or item
C35738:  CMP #$FF        ; Empty slot?
         BEQ C3576D      ; Blank if so
         REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAY             ; Index it
         LDA [$E7],Y     ; Relative ptr
         TAY             ; Index it
         SEP #$20        ; 8-bit A
C35745:  LDA [$EB],Y     ; Text character
         BEQ C3574F      ; Branch if 00h
         STA $2180       ; Add to string
         INY             ; Index +1
         BRA C35745      ; Do next char

; Fork: Check if terminator (SFC)
C3574F:  DEY             ; Index -1
         LDA [$EB],Y     ; Previous char
         INY             ; Index +1
         CMP #$1C        ; Command 1C?
         BEQ C35767      ; Branch if so
         CMP #$1D        ; Command 1D?
         BEQ C35767      ; Branch if so
         CMP #$1E        ; Command 1E?
         BEQ C35767      ; Branch if so
         CMP #$1F        ; Command 1F?
         BEQ C35767      ; Branch if so
C35763:  STZ $2180       ; End string
         RTS

; Fork: Resume past control code (SFC)
C35767:  STZ $2180       ; Add 00h to msg
         INY             ; Index +1
         BRA C35745      ; Do next char

; Fork: Empty slot (space is for item usage menu)
C3576D:  LDA #$FF        ; Space char
         STA $2180       ; Add to string
         BRA C35763      ; End string

; Draw Dance list and menu title, create portrait
C35774:  JSR C36A15      ; Clear BG1 map A
         JSR C3578A      ; Draw Dance list
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         LDY #C35C9F     ; Text pointer
         JSR C302F9      ; Draw "Dance"
         JSR C361AC      ; Create portrait
         JMP C30F4D      ; Queue BG3 upload

; Build and draw Dance list
C3578A:  JSR C35620      ; Build Dance list
         JSR C383F7      ; Define $E5, $E6
         INC $E6         ; BG1 write row +1
         STZ $E5         ; Dance slot: 1
         LDY #$0004      ; Rows left: 4
C35797:  PHY             ; Save counter
         JSR C357AA      ; Draw 2 dances
         LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         INC A           ; Go 1 row down
         INC A           ; Go 1 row down
         INC A           ; Go 1 row down
         AND #$1F        ; Stay in limits
         STA $E6         ; Save changes
         PLY             ; Rows left
         DEY             ; One less left
         BNE C35797      ; Loop till last
         RTS

; Draw a row of two Dance names
C357AA:  JSR C357C1      ; Define source
         LDX #$0003      ; X: 3
         JSR C357D0      ; Draw Dance A
         INC $E5         ; Dance slot +1
         JSR C357C1      ; Define source
         LDX #$0011      ; X: 17
         JSR C357D0      ; Draw Dance B
         INC $E5         ; Dance slot +1
         RTS

; Set source for loading Dance name
C357C1:  LDY #$000C      ; Letters: 12
         STY $EB         ; Set src size
         LDY #$FF9D      ; E6/FF9D
         STY $EF         ; Set src LBs
         LDA #$E6        ; Bank: E6
         STA $F1         ; Set src HB
         RTS

; Draw Dance name
C357D0:  LDA $E6         ; BG1 write row
         JSR C3809F      ; Compute map ptr
         REP #$20        ; 16-bit A
         TXA             ; ...
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $E5         ; Dance slot
         TAX             ; Index it
         LDA $7E9D89,X   ; Dance in slot
         CMP #$FF        ; Empty slot?
         BEQ C357F0      ; Blank if so
         JSR C38467      ; Load name
         JMP C37FD9      ; Draw name

; Fork: Blank Dance slot
C357F0:  LDY #$000C      ; Spaces: 12
         LDX #$9E8B      ; 7E/9E8B
         STX $2181       ; Set WRAM LBs
         LDA #$FF        ; Space char
C357FB:  STA $2180       ; Add to string
         DEY             ; One less left
         BNE C357FB      ; Loop till last
         STZ $2180       ; End string
         JMP C37FD9      ; Draw 12 spaces

; Set to delete portrait in Skills menu
C35807:  TDC             ; Clear A
         LDA $60         ; Queue index
         TAX             ; Index it
         LDA #$FF        ; Null value
         STA $7E35C9,X   ; Portrait: Off
         RTS

; Draw and upload spell usage menu
C35812:  JSR C36A28      ; Clear BG2 map A
         LDY #C3583F     ; C3/583F
         JSR C30341      ; Draw party box
         LDY #C35843     ; C3/5843
         JSR C30341      ; Draw spell box
         LDY #C35847     ; C3/5847
         JSR C30341      ; Draw cost box
         JSR C30E52      ; Upload windows
         JSR C36A19      ; Clear BG1 map B
         LDY #$FFC0      ; X: -64 = 448
         STY $35         ; Set BG1 X-Pos
         LDA #$02        ; Portrait row bit
         TSB $45         ; Ignore back row
         JSR C3318A      ; Draw party info
         JSR C3584B      ; Draw spell, cost
         JMP C3319F      ; Upload text maps

; Window layout for spell usage menu
C3583F:  dw $589D,$1813  ; 21x26 at $589D (Party)
C35843:  dw $588B,$0207  ; 09x04 at $588B (Spell)
C35847:  dw $598B,$0307  ; 09x05 at $598B (MP cost)

; Draw spell name and cost message for spell usage menu
C3584B:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDY #C35889     ; Text pointer
         JSR C302F9      ; Draw "MP"
         LDY #C3588E     ; Text pointer
         JSR C302F9      ; Draw "Needed"
         TDC             ; ...
         LDA $4B         ; Cursor slot
         STA $E5         ; Set spell slot
         JSR C34FB5      ; Define source
         REP #$20        ; 16-bit A
         LDA #$790D      ; Tilemap ptr
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         JSR C350EC      ; Spell
         JSR C38467      ; Load spell name
         JSR C37FD9      ; Draw spell name
         JSR C350EC      ; Spell
         JSR C3510D      ; Define MP cost
         JSR C304E0      ; Turn into text
         LDX #$7A0F      ; Text position
         JSR C304B6      ; Draw 2 digits
         JMP C37FD9      ; Redraw name...

; Positioned text, "MP Needed"
C35889:  dw $7A15 : db "MP",$00
C3588E:  dw $7A4D : db "Needed",$00

; Initialize esper data menu
C35897:  LDY $4F         ; Cursor position
         STY $8E         ; Set return loc
         LDA $4A         ; Scroll position
         STA $90         ; Set return loc
         JSR C35B54      ; Load esper info
         JSR C3599F      ; Draw esper info
         JSR C30F11      ; Queue its upload
         JSR C31368      ; Upload it now
         JSR C30EFD      ; Requeue esper list
         REP #$20        ; 16-bit A
         LDA #$0100      ; BG1 H-Shift: 256
         STA $7E9A10     ; Hide esper list
         SEP #$20        ; 8-bit A
         LDA $49         ; Top BG1 write row
         STA $5F         ; Save for return
         LDA #$07        ; BG1 VRAM row: 7
         STA $49         ; Save for V-Shift
         JSR C34E2D      ; Load V-shift data
         LDA #$C0        ; Scrollbar: Off
         TRB $46         ; Set anim index
         JSR C3597D      ; Load navig data
         JMP C35986      ; Relocate cursor

; 4D: Sustain esper data menu
C358CE:  JSR C35983      ; Handle D-Pad
         JSR C35B93      ; Load description
         LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C3590A      ; Branch if not
         TDC             ; Clear A
         LDA $4B         ; On esper name?
         BNE C3590A      ; Branch if not
         LDA $99         ; Viewed esper
         JSR C35574      ; Choose palette
         STA $E0         ; Memorize esper
         LDA $29         ; Esper palette
         CMP #$28        ; Grayed out?
         BNE C35902      ; Equip if not
         JSR C30EC0      ; Play buzzer
         LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         JSR C3559A      ; Draw who has it
         LDY #$0020      ; Frames: 32
         STY $20         ; Set exit delay
         LDA #$34        ; C3/293A
         STA $26         ; Next: Late exit
         JMP C30F11      ; Queue text upload

; Fork: Equip esper
C35902:  JSR C30EB2      ; Sound: Click
         JSR C32929      ; Equip/draw esper
         BRA C35913      ; Exit submenu

; Fork: Handle B
C3590A:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C3597C      ; Exit if not
         JSR C30EA9      ; Sound: Cursor
C35913:  LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         LDA $5F         ; Top BG1 write row
         STA $49         ; Restore it
         JSR C3546C      ; Draw esper list
         JSR C3091F      ; Create scrollbar
         REP #$20        ; 16-bit A
         LDA #$1000      ; V-Speed: 16 px
         STA $7E354A,X   ; Set scrollbar's
         LDA #$0060      ; Y: 96
         STA $7E34CA,X   ; Set scrollbar's
         SEP #$20        ; 8-bit A
         JSR C34C18      ; Load navig data
         LDA $8E         ; Old cursor column
         STA $4D         ; Set onscreen col
         LDY $8E         ; Old cursor loc
         STY $4F         ; Set as current
         LDA $90         ; Old scroll pos
         STA $4A         ; Set as current
         LDA $4A         ; ...
         STA $E0         ; Memorize it...
         LDA $50         ; List row
         SEC             ; Prepare SBC
         SBC $E0         ; Deduct scroll pos
         STA $4E         ; Set cursor row
         JSR C34C21      ; Relocate cursor
         LDA #$06        ; Top row: Golem's
         STA $5C         ; Set scroll limit
         LDA #$08        ; Onscreen rows: 8
         STA $5A         ; Set rows per page
         LDA #$02        ; Onscreen cols: 2
         STA $5B         ; Set cols per page
         JSR C30EFD      ; Queue list upload
         JSR C31368      ; Refresh esper list
         REP #$20        ; 16-bit A
         TDC             ; BG1 H-Shift: 0
         STA $7E9A10     ; Unhide esper list
         SEP #$20        ; 8-bit A
         LDY #$0100      ; X: 256
         STY $39         ; Set BG2 X-Pos
         STY $3D         ; Set BG3 X-Pos
         JSR C34E2D      ; Load V-shift data
         JSR C30F11      ; Queue stats upload
         LDA #$1E        ; C3/28D3
         STA $26         ; Next: Esper choice
C3597C:  RTS

; Load navigation data for esper data menu
C3597D:  LDY #C3598C     ; C3/598C
         JMP C305FE      ; Load navig data

; Handle D-Pad for esper data menu
C35983:  JSR C3072D      ; Handle D-Pad
C35986:  LDY #C35991     ; C3/5991
         JMP C30640      ; Relocate cursor

; Navigation data for esper data menu
C3598C:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $07          ; 7 rows

; Cursor positions for esper data menu
C35991:  dw $7010        ; Esper
         dw $7C18        ; Spell A
         dw $8818        ; Spell B
         dw $9418        ; Spell C
         dw $A018        ; Spell D
         dw $AC18        ; Spell E
         dw $B818        ; Bonus

; Draw selected esper's info
C3599F:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDY #C35CEA     ; Text pointer
         JSR C302F9      ; Do "Learn.Rate"
         LDY #C35CE2     ; Text pointer
         JSR C302F9      ; Draw "Skill"
         LDA $99         ; Viewed esper
         JSR C35574      ; Choose palette
         LDY #$4411      ; Tilemap ptr
         JSR C33519      ; Set pos, WRAM
         TDC             ; ...
         LDA $99         ; Viewed esper
         ASL A           ; x2
         ASL A           ; x4
         ASL A           ; x8
         TAX             ; Index it
         LDY #$0008      ; Letters: 8
C359C4:  LDA $E6F6E1,X   ; Esper name char
         STA $2180       ; Add to string
         INX             ; Point to next
         DEY             ; One less left
         BNE C359C4      ; Loop till last
         STZ $2180       ; End string
         JSR C37FD9      ; Draw esper name

; Fork: Draw spell data
C359D5:  TDC             ; Clear A
         LDA $4B         ; Selected slot
         TAX             ; Index it
         LDA $7E9D89,X   ; Esper in slot
         STA $4202       ; Set multiplicand
         LDA #$0B        ; Esper data size
         STA $4203       ; Set multiplier
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDY #$0011      ; Y: 17
         STY $F5         ; Memorize it
         REP #$20        ; 16-bit A
         LDA $4216       ; Product
         TAX             ; Index it
C359F4:  SEP #$20        ; 8-bit A
         LDA $D86E00,X   ; Learning rate
         STA $E0         ; Memorize it
         INX             ; Index +1
         LDA $D86E00,X   ; Spell
         STA $E1         ; Memorize it
         INX             ; Index +1
         PHX             ; Save index
         LDX #$0005      ; X: 5
         LDY $F5         ; Y position
         LDA $E1         ; Spell
         PHA             ; Preserve it
         JSR C35AE1      ; Draw spell, rate
         LDX #$0018      ; X: 24
         LDY $F5         ; Y position
         PLA             ; Spell
         STA $E1         ; Restore it
         JSR C35A84      ; Draw percentage
         PLX             ; Spell data index
         REP #$20        ; 16-bit A
         INC $F5         ; Y position +1
         INC $F5         ; Y position +1
         LDA $F5         ; Y position
         CMP #$001B      ; Done 5 spells?
         BNE C359F4      ; Loop if not

; Fork: Draw esper bonus message
C35A29:  SEP #$20        ; 8-bit A
         LDA $D86E00,X   ; Esper bonus
         CMP #$FF        ; None?
         BEQ C35A67      ; Blank if so
         STA $4202       ; Set multiplicand
         LDA #$09        ; Text length
         STA $4203       ; Set multiplier
         LDY #$4713      ; Tilemap ptr
         JSR C33519      ; Set pos, WRAM
         LDX $00         ; Char index: 0
C35A43:  LDA.L C35CF7,X  ; "At..." char
         STA $2180       ; Add to string
         INX             ; Point to next
         CPX #$000E      ; Done all 14?
         BNE C35A43      ; Loop if not
         LDX $4216       ; Index product
         LDY #$0009      ; Letters: 9
C35A56:  LDA $CFFEAE,X   ; Bonus char
         STA $2180       ; Add to string
         INX             ; Point to next
         DEY             ; One less left
         BNE C35A56      ; Loop till last
         STZ $2180       ; End string
         JMP C37FD9      ; Draw string

; Fork: Blank esper bonus message
C35A67:  LDY #$4713      ; Tilemap ptr
         JSR C33519      ; Set pos, WRAM
         LDY #$0017      ; Letters: 23
         LDX #$9E8B      ; 7E/9E8B
         STX $2181       ; Set WRAM LBs
         LDA #$FF        ; Space char
C35A78:  STA $2180       ; Add to string
         DEY             ; One less left
         BNE C35A78      ; Loop till last
         STZ $2180       ; End string
         JMP C37FD9      ; Draw 23 spaces

; Draw spell's mastery percentage for esper data menu
C35A84:  JSR C35B3D      ; Compute map ptr
         REP #$20        ; 16-bit A
         TXA             ; ...
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         LDX #$9E8B      ; 7E/9E8B
         STX $2181       ; Set WRAM LBs
         LDA $E1         ; Spell
         CMP #$FF        ; None?
         BEQ C35AD1      ; Blank if so
         JSR C350A2      ; Spell mastery
         CMP #$FF        ; Fully learned?
         BEQ C35AC2      ; Branch if so
         PHA             ; Save mastery
         LDA #$FF        ; Space char
         STA $2180       ; Add to string
         PLA             ; Spell mastery
         JSR C304E0      ; Turn into text
         LDA $F8         ; Tens digit
         STA $2180       ; Add to string
         LDA $F9         ; Ones digit
         STA $2180       ; Add to string
C35AB7:  LDA.B #!perc    ; Char: "%"
         STA $2180       ; Add to string
C35ABC:  STZ $2180       ; End string
         JMP C37FD9      ; Draw string

; Fork: Draw "100%"
C35AC2:  LDA.B #!num1    ; Char: "1"
         STA $2180       ; Add to string
         LDA.B #!num0    ; Char: "0"
         STA $2180       ; Add to string
         STA $2180       ; Add to string
         BRA C35AB7      ; Add "%"; draw

; Fork: Blank percentage
C35AD1:  LDA #$FF        ; Space char
         STA $2180       ; Add to string
         STA $2180       ; Add to string
         STA $2180       ; Add to string
         STA $2180       ; Add to string
         BRA C35ABC      ; Draw 4 spaces

; Draw spell's name and learning rate
C35AE1:  JSR C35B3D      ; Compute map ptr
         REP #$20        ; 16-bit A
         TXA             ; ...
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
C35AED:  JSR C34FB5      ; Define source
         LDA $E1         ; Spell
         CMP #$FF        ; None?
         BEQ C35B26      ; Blank if so
         JSR C38467      ; Load name
         LDX #$9E92      ; 7E/9E92
         STX $2181       ; Set WRAM LBs
         LDA.B #!coln    ; Char: ":"
         STA $2180       ; Add to string
         LDA #$FF        ; Space char
         STA $2180       ; Add to string
         STA $2180       ; Add to string
         LDA.B #!mult    ; Char: "×"
         STA $2180       ; Add to string
         LDA $E0         ; Learning rate
         JSR C304E0      ; Turn into text
         LDA $F8         ; Tens digit
         STA $2180       ; Add to string
         LDA $F9         ; Ones digit
         STA $2180       ; Add to string
         STZ $2180       ; End string
         JMP C37FD9      ; Draw string

; Fork: No spell
C35B26:  LDY #$000F      ; Spaces: 15
         LDX #$9E8B      ; 7E/9E8B
         STX $2181       ; Set WRAM LBs
         LDA #$FF        ; Space char
C35B31:  STA $2180       ; Add to string
         DEY             ; One less left
         BNE C35B31      ; Loop till last
         STZ $2180       ; End string
         JMP C37FD9      ; Draw 15 spaces

; Compute position into BG1 tilemap B
C35B3D:  REP #$20        ; 16-bit A
         TYA             ; Y position
         ASL A           ; x2
         ASL A           ; x4
         ASL A           ; x8
         ASL A           ; x16
         ASL A           ; x32
         ASL A           ; x64
         STA $E7         ; Memorize it
         TXA             ; X position
         ASL A           ; Double it
         CLC             ; ...
         ADC $E7         ; Add Y x64
         ADC #$4049      ; Add base adr
         TAX             ; Put in X...
         SEP #$20        ; 8-bit A...
         RTS

; Load esper's info for display
C35B54:  TDC             ; Clear A...
         LDA $99         ; Chosen esper
         STA $7EAB8D     ; Add to list
         LDA $4B         ; Chosen slot...
         TAX             ; Index it...
         LDA $7E9D89,X   ; Chosen esper...
         STA $4202       ; Set multiplicand
         LDA #$0B        ; Esper data size
         STA $4203       ; Set multiplier
         PHB             ; Save DB
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         LDY #$0001      ; Spell slot: 1
         REP #$20        ; 16-bit A
         LDA $004216     ; Product
         TAX             ; Index it
         SEP #$20        ; 8-bit A
C35B7B:  INX             ; Skip Learn.Rate
         LDA $D86E00,X   ; Spell taught
         STA $AB8D,Y     ; Add to list
         INX             ; ROM index +1
         INY             ; RAM index +1
         CPY #$0006      ; Done 5 spells?
         BNE C35B7B      ; Loop if not
         LDA $D86E00,X   ; Level up bonus
         STA $AB93       ; Add to list
         PLB             ; Restore DB
         RTS

; Load description for esper data menu
C35B93:  LDX #$9EC9      ; 7E/9EC9
         STX $2181       ; Set WRAM LBs
         TDC             ; Clear A
         LDA $4B         ; Cursor row
         TAX             ; Index it
         LDA $7EAB8D,X   ; Slot content
         CMP #$FF        ; Empty slot?
         BEQ C35BD1      ; Blank if so
         PHA             ; Memorize it
         JSR C35BDB      ; Load pointers
         PLA             ; Slot content
         REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAY             ; Index it
         LDA [$E7],Y     ; Relative ptr
         TAY             ; Index it
         SEP #$20        ; 8-bit A
C35BB3:  LDA [$EB],Y     ; Text character
         BEQ C35BBD      ; Branch if 00h
         STA $2180       ; Add to string
         INY             ; Index +1
         BRA C35BB3      ; Do next char

; Fork: Check if terminator (SFC)
C35BBD:  DEY             ; Index -1
         LDA [$EB],Y     ; Previous char
         INY             ; Index +1
         CMP #$1C        ; Command 1C?
         BEQ C35BD5      ; Branch if so
         CMP #$1D        ; Command 1D?
         BEQ C35BD5      ; Branch if so
         CMP #$1E        ; Command 1E?
         BEQ C35BD5      ; Branch if so
         CMP #$1F        ; Command 1F?
         BEQ C35BD5      ; Branch if so
C35BD1:  STZ $2180       ; End string
         RTS

; Fork: Resume past control code (SFC)
C35BD5:  STZ $2180       ; Add 00h to msg
         INY             ; Index +1
         BRA C35BB3      ; Do next char

; Load description pointers for esper data menu
C35BDB:  LDA $4B         ; On esper name?
         BEQ C35C09      ; Branch if so
         CMP #$06        ; On bonus?
         BEQ C35BF6      ; Branch if so

; Fork: Magic effect
C35BE3:  LDX #$CF80      ; D8/CF80
         STX $E7         ; Set ptr loc LBs
         LDX #$C9A0      ; D8/C9A0
         STX $EB         ; Set text loc LBs
         LDA #$D8        ; Bank: D8
         STA $E9         ; Set ptr loc HB
         LDA #$D8        ; ...
         STA $ED         ; Set text loc HB
         RTS

; Fork: Level up bonus
C35BF6:  LDX #$FFD0      ; ED/FFD0
         STX $E7         ; Set ptr loc LBs
         LDX #$FE00      ; ED/FE00
         STX $EB         ; Set text loc LBs
         LDA #$ED        ; Bank: ED
         STA $E9         ; Set ptr loc HB
         LDA #$ED        ; ...
         STA $ED         ; Set text loc HB
         RTS

; Fork: Esper effect
C35C09:  LDX #$FE40      ; CF/FE40
         STX $E7         ; Set ptr loc LBs
         LDX #$3940      ; CF/3940
         STX $EB         ; Set text loc LBs
         LDA #$CF        ; Bank: CF
         STA $E9         ; Set ptr loc HB
         LDA #$CF        ; ...
         STA $ED         ; Set text loc HB
         RTS

; Tile attributes for Blitz inputs
C35C1C:  dw $0000        ; Terminator
         dw $0000        ; Bogus; for A
         dw $0000        ; Bogus; for B
         dw $2097        ; X
         dw $2098        ; Y
         dw $208B        ; L
         dw $2091        ; R
         dw $20D6        ; Down-left
         dw $A0D4        ; Down
         dw $60D6        ; Down-right
         dw $20D5        ; Right
         dw $C0D6        ; Up-right
         dw $20D4        ; Up
         dw $A0D6        ; Up-left
         dw $60D5        ; Left

; Text pointers for Skills menu (unused)
C35C3A:  dw C35C48       ; Espers
         dw C35C51       ; Magic
         dw C35C59       ; SwdTech
         dw C35C63       ; Blitz
         dw C35C6B       ; Lore
         dw C35C72       ; Rage
         dw C35C79       ; Dance

; Positioned text for Skills menu
C35C48:  dw $790D : db "Espers",$00
C35C51:  dw $798D : db "Magic",$00
C35C59:  dw $7A8D : db "SwdTech",$00
C35C63:  dw $7B0D : db "Blitz",$00
C35C6B:  dw $7B8D : db "Lore",$00
C35C72:  dw $7C0D : db "Rage",$00
C35C79:  dw $7C8D : db "Dance",$00

; Text pointers for Skills menu
C35C81:  dw C35CC2       ; LV
         dw C35CC7       ; HP
         dw C35CCC       ; MP

; Positioned text for Skills submenus
C35C87:  dw $81B7 : db "MP…    ",$00
C35C91:  dw $81B7 : db "Lore",$00
C35C98:  dw $81B7 : db "Rage",$00
C35C9F:  dw $81B7 : db "Dance",$00
C35CA7:  dw $81B7 : db "Espers",$00
C35CB0:  dw $81B7 : db "Blitz",$00
C35CB8:  dw $81B7 : db "SwdTech",$00
C35CC2:  dw $422D : db "LV",$00
C35CC7:  dw $42AD : db "HP",$00
C35CCC:  dw $432D : db "MP",$00
C35CD1:  dw $42BB : db "/",$00
C35CD5:  dw $433B : db "/",$00
C35CD9:             db " has it!",$00
C35CE2:  dw $4439 : db "Skill",$00
C35CEA:  dw $4423 : db "Learn.Rate",$00
C35CF7:           : db "At level up..."

; Draw and upload Status menu, create portrait
C35D05:  JSR C35D17      ; Draw main windows
         JSR C35DC1      ; Draw Gogo's panel
         JSR C35D3C      ; Draw blue text
         JSR C35F8D      ; Draw actor info
         JSR C35D77      ; Upload tilemaps
         JMP C361AC      ; Create portrait

; Draw windows for non-shifted Status menu
C35D17:  JSR C36A15      ; Clear BG1 map A
         JSR C36A23      ; Clear BG1 map D
         JSR C36A3C      ; Clear BG3 map A
         JSR C36A41      ; Clear BG3 map B
         JSR C36A46      ; Clear BG3 map C
         JSR C36A4B      ; Clear BG3 map D
         LDY #C35F81     ; C3/5F81
         JSR C30341      ; Draw main window
         LDY #C35F79     ; C3/5F79
         JSR C30341      ; Draw title window
         LDY #C35F7D     ; C3/5F7D
         JSR C30341      ; Draw cmd window
         RTS

; Draw blue text and non-blue symbols in Status menu
C35D3C:  JSR C35D41      ; LV, HP, MP, %, /
         BRA C35D5C      ; Rest of blue text

; Draw LV, HP, MP, and non-blue symbols in Status menu
C35D41:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDX #C3645B     ; Text ptrs loc
         LDY #$0008      ; Strings: 4
         JSR C369BA      ; Draw 2x / and %
         LDA #$24        ; Palette 1
         STA $29         ; Color: Blue
         LDX #C36455     ; Text ptrs loc
         LDY #$0006      ; Strings: 3
         JSR C369BA      ; Draw "LV/HP/MP"
         RTS

; Draw all blue text in Status menu except LV, HP, and MP
C35D5C:  LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         LDX #C36437     ; Text ptrs loc
         LDY #$001E      ; Strings: 15
         JSR C369BA      ; Draw Vigor, etc.
         LDA #$2C        ; ...
         STA $29         ; ...
         LDX #C36463     ; Text ptrs loc
         LDY #$000C      ; Strings: 6
         JSR C369BA      ; Draw Speed, etc.
         RTS

; Upload tilemaps for Status menu
C35D77:  JSR C30E52      ; Upload BG2 A+B
         JSR C30E28      ; Upload BG1 A+B
         JSR C30E6E      ; Upload BG3 A+B
         JMP C30E7C      ; Upload BG3 C+D

; Handle member switching in Status menu
C35D83:  JSR C35D41      ; Draw "MP" + "/"
         JSR C35F8D      ; Draw actor info
         JSR C361A2      ; Create portrait
         LDY #$0000      ; $0000 = BG1a
         STY $14         ; Set VRAM ptr A
         LDY #$3849      ; 7E/3849
         STY $16         ; Set src-a LBs
         LDY #$0800      ; Bytes: 2048
         STY $12         ; Set src-a size
         LDY #$4000      ; $8000 = BG3a
         STY $1B         ; Set VRAM ptr B
         LDY #$7849      ; 7E/7849
         STY $1D         ; Set src-b LBs
         LDY #$0800      ; Bytes: 2048
         STY $19         ; Set src-b size
         JSR C311B0      ; Swap portraits
         JSR C31368      ; Trigger NMI
         LDY $00         ; Null value
         STY $1B         ; Dequeue BG3a
         LDY #$4800      ; $9000 = BG3c
         STY $14         ; Set VRAM ptr
         LDY #$8849      ; 7E/8849
         STY $16         ; Set src LBs
         JMP C31368      ; Upload BG3c

; Draw Gogo's list of available commands, prepare portrait hiding
C35DC1:  LDX #$9E09      ; 7E/9E09
         STX $2181       ; Set WRAM LBs
         TDC             ; Clear A

; Fork: Compile everyone's commands, exclude guests and dead Shadow
C35DC8:  TAX             ; 1st: Terra
C35DC9:  PHX             ; Save char slot
         REP #$20        ; 16-bit A
         TXA             ; Actor slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA $1EDC       ; Eligible actors
         AND.L C39C67,X  ; Has our actor?
         BEQ C35DFB      ; Skip if not
         REP #$20        ; ...
         LDA.L C36969,X  ; Actor's address
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDA $0016,X     ; Command 1
         STA $2180       ; Add to list
         LDA $0017,X     ; Command 2
         STA $2180       ; Add to list
         LDA $0018,X     ; Command 3
         STA $2180       ; Add to list
         LDA $0019,X     ; Command 4
         STA $2180       ; Add to list
         BRA C35E0B      ; Do next actor
C35DFB:  SEP #$20        ; 8-bit A
         LDA #$FF        ; Command: None
         STA $2180       ; Set command 1
         STA $2180       ; Set command 2
         STA $2180       ; Set command 3
         STA $2180       ; Set command 4
C35E0B:  PLX             ; Actor slot
         INX             ; Actor slot +1
         CPX #$0010      ; Done 16 actors?
         BNE C35DC9      ; Loop if not

; Fork: Delete duplicates
C35E12:  TDC             ; Clear A
         TAX             ; Cmd slot: 1
C35E14:  PHX             ; Save cmd slot
         LDA $7E9E09,X   ; Available cmd
C35E19:  CMP $7E9E0A,X   ; Duplicate?
         BNE C35E27      ; Branch if not
         PHA             ; Save command
         LDA #$FF        ; Command: None
         STA $7E9E0A,X   ; Clear duplicate
         PLA             ; Battle command
C35E27:  INX             ; Cmd slot +1
         CPX #$0040      ; Done 16 x 4?
         BNE C35E19      ; Loop if not
         PLX             ; Base cmd slot
         INX             ; Cmd slot +1
         CPX #$0040      ; Done 16 x 4?
         BNE C35E14      ; Loop if not

; Fork: Build final command list
C35E34:  LDX #$9D8A      ; 7E/9D8A
         STX $2181       ; Set WRAM LBs
         LDA #$FF        ; Cmd: Empty
         STA $2180       ; Add to list
         TDC             ; Clear A
         TAX             ; Cmd slot: 1
         TAY             ; Cmd count: 0
C35E42:  TDC             ; ...
         PHX             ; Save cmd slot
         LDA $7E9E09,X   ; Available cmd
         BMI C35E60      ; Skip if none
         CMP #$12        ; Mimic?
         BEQ C35E60      ; Skip if so
         STA $E0         ; Memorize it
         ASL A           ; Double it
         TAX             ; Index it
         LDA $CFFE00,X   ; Properties
         AND #$01        ; Gogo can use?
         BEQ C35E60      ; Skip if not
         LDA $E0         ; Command
         STA $2180       ; Add to list
         INY             ; Cmd count +1
C35E60:  PLX             ; Cmd slot
         INX             ; Cmd slot +1
         CPX #$0040      ; Done 16 x 4?
         BNE C35E42      ; Loop if not
         INY             ; Cmd count +1
         TYA             ; Put it in A
         STA $7E9D89     ; Set list size

; Fork: Load window layout for command list
C35E6D:  LDX #$AA8D      ; 7E/AA8D
         STX $2181       ; Set WRAM LBs
         TDC             ; Clear A
         TAX             ; Index: 0
C35E75:  LDA.L C35F85,X  ; Window data
         STA $2180       ; Save in WRAM
         INX             ; Index +1
         CPX #$0008      ; End of table?
         BNE C35E75      ; Loop if not

; Fork: Draw both segments of command window
C35E82:  TYA             ; Command count
         STA $E2         ; Memorize it
         CLC             ; Prepare ADC
         ADC $E2         ; x2
         ADC $E2         ; x3
         AND #$FE        ; -1 if odd
         BEQ C35E90      ; Branch if no cmd
         INC A           ; +1
         INC A           ; +1
C35E90:  LSR A           ; ÷2
         STA $7EAA90     ; Set L-Win heigth
         STA $7EAA94     ; Set R-Win heigth
         LDY #$AA8D      ; 7E/AA8D
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         JSR C30345      ; Draw left box
         LDY #$AA91      ; 7E/AA91
         LDA #$7E        ; ...
         STA $E9         ; ...
         JSR C30345      ; Draw right box

; Fork: Draw command list, prepare portrait hiding
C35EAD:  LDA $7E9D89     ; List size
         STA $E5         ; Memorize it
         STZ $E6         ; Clear HB
         TDC             ; Clear A
         TAX             ; Cmd slot: 1
         LDY #$80C9      ; Tilemap ptr
C35EBA:  PHX             ; Save cmd slot
         PHY             ; Save position
         LDA $7E9D8A,X   ; Available cmd
         JSR C35ED7      ; Draw cmd name
         PLY             ; Text position
         REP #$20        ; 16-bit A
         TYA             ; Put in A
         CLC             ; Prepare ADC
         ADC #$0080      ; +2 rows down
         TAY             ; Put in Y
         SEP #$20        ; 8-bit A
         PLX             ; Cmd slot
         INX             ; Cmd slot +1
         CPX $E5         ; End of list?
         BNE C35EBA      ; Loop if not
         JMP C35F50      ; Set hiding spot

; Draw battle command name, ignore modifiers
C35ED7:  PHA             ; Save command
         JSR C33519      ; Set pos, WRAM
         PLA             ; Battle command
         BMI C35F0C      ; Blank if none
         JMP C35EE6      ; Draw cmd name

; Draw battle command name, apply modifiers
C35EE1:  JSR C3612C      ; Apply modifiers
         BMI C35F0C      ; Blank if no cmd
C35EE6:  JSR C35F25      ; Pick a palette
         STA $E2         ; Save command
         PHA             ; Memorize it
         ASL A           ; x2
         ASL A           ; x4
         STA $E0         ; Memorize it
         PLA             ; Command
         ASL A           ; x2
         CLC             ; ...
         ADC $E0         ; x6
         ADC $E2         ; x7
         TAX             ; Index it
         LDY #$0007      ; Letters: 7
C35EFB:  LDA $D8CEA0,X   ; Letter
         STA $2180       ; Add to string
         INX             ; Point to next
         DEY             ; One less left
         BNE C35EFB      ; Loop till last
C35F06:  STZ $2180       ; End string
         JMP C37FD9      ; Draw cmd name

; Fork: Blank command slot
C35F0C:  LDA #$FF        ; Space char
         STA $2180       ; Add to string
         STA $2180       ; Add to string
         STA $2180       ; Add to string
         STA $2180       ; Add to string
         STA $2180       ; Add to string
         STA $2180       ; Add to string
         STA $2180       ; Add to string
         BRA C35F06      ; Draw 7 spaces

; Select a palette for battle command
C35F25:  PHA             ; Save command
         CMP #$0B        ; Runic?
         BEQ C35F3A      ; Branch if so
         CMP #$07        ; SwdTech?
         BEQ C35F44      ; Branch if so
C35F2E:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         PLA             ; Command
         RTS

; Fork: Set to gray
C35F34:  LDA #$24        ; Palette 1
         STA $29         ; Color: Gray
         PLA             ; Command
         RTS

; Fork: Handle Runic
C35F3A:  LDA $11DA       ; R-Hand can Runic?
         ORA $11DB       ; Or L-Hand?
         BPL C35F34      ; Gray out if not
         BRA C35F2E      ; Use user's color

; Fork: Handle SwdTech
C35F44:  LDA $11DA       ; R-Hand flags
         ORA $11DB       ; Add L-Hand's
         BIT #$02        ; Can use SwdTech?
         BEQ C35F34      ; Gray out if not
         BRA C35F2E      ; Use user's color

; Set a section of Status menu to mask wrapping Gogo portrait
C35F50:  LDX #$61CA      ; Tilemap ptr
         STX $E7         ; Set dst LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set dst HB
         LDX #$0006      ; Rows left: 6
C35F5C:  TDC             ; Clear A
         TAY             ; Map index: 0
         LDA #$3D        ; Pal 7, priority
C35F60:  STA [$E7],Y     ; Set attributes
         INY             ; Index +1
         INY             ; Index +1
         CPY #$0012      ; Done 9 tiles?
         BNE C35F60      ; Loop if not
         REP #$20        ; 16-bit A
         LDA $E7         ; Tilemap ptr
         CLC             ; Prepare ADC
         ADC #$0040      ; Go 1 row down
         STA $E7         ; Save changes
         SEP #$20        ; 8-bit A
         DEX             ; One less row
         BNE C35F5C      ; Loop till last
         RTS

; Window layout for Status menu
C35F79:  dw $588B,$0106  ; 08x03 at $588B (Title)
C35F7D:  dw $5AEB,$0609  ; 11x08 at $5AEB (Commands)
C35F81:  dw $588B,$181C  ; 30x26 at $588B (Main)
C35F85:  dw $58C7,$1200  ; 02x20 at $58C7 (Gogo, L part)
C35F89:  dw $6087,$1207  ; 09x20 at $6087 (Gogo, R part)

; Draw actor info in Status menu
C35F8D:  TDC             ; Clear A
         LDA $28         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C35F95,X)  ; Draw info

; Jump table for the above
C35F95:  dw C35F9D       ; Member 1
         dw C35FA7       ; Member 2
         dw C35FB1       ; Member 3
         dw C35FBB       ; Member 4

; Draw member 1's info in Status menu
C35F9D:  LDX $6D         ; Actor address
         STX $67         ; Memorize it
         TDC             ; ...
         LDA $69         ; Actor
         JMP C35FC2      ; Draw info

; Draw member 2's info in Status menu
C35FA7:  LDX $6F         ; Actor address
         STX $67         ; Memorize it
         TDC             ; ...
         LDA $6A         ; Actor
         JMP C35FC2      ; Draw info

; Draw member 3's info in Status menu
C35FB1:  LDX $71         ; Actor address
         STX $67         ; Memorize it
         TDC             ; ...
         LDA $6B         ; Actor
         JMP C35FC2      ; Draw info

; Draw member 4's info in Status menu
C35FBB:  LDX $73         ; Actor address
         STX $67         ; Memorize it
         TDC             ; ...
         LDA $6C         ; Actor
C35FC2:  JSL $C20006     ; Load properties
         LDY $67         ; Actor's address
         JSR C399E8      ; Set Bat.Pwr mode
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDA $11A6       ; Vigor
         JSR C304E0      ; Turn into text
         LDX #$7EE1      ; Text position
         JSR C304C0      ; Draw 3 digits
         LDA $11A4       ; Speed
         JSR C304E0      ; Turn into text
         LDX #$7F61      ; Text position
         JSR C304C0      ; Draw 3 digits
         LDA $11A2       ; Stamina
         JSR C304E0      ; Turn into text
         LDX #$7FE1      ; Text position
         JSR C304C0      ; Draw 3 digits
         LDA $11A0       ; Mag.Pwr
         JSR C304E0      ; Turn into text
         LDX #$8861      ; Text position
         JSR C304C0      ; Draw 3 digits
         JSR C39371      ; Define Bat.Pwr
         LDA $11AC       ; ...
         CLC             ; ...
         ADC $11AD       ; ...
         STA $F3         ; ...
         TDC             ; ...
         ADC #$00        ; ...
         STA $F4         ; ...
         JSR C3052E      ; Turn into text
         LDX #$7E7D      ; Text position
         JSR C30486      ; Draw 3 digits
         LDA $11BA       ; Defense
         JSR C304E0      ; Turn into text
         LDX #$7EFD      ; Text position
         JSR C304C0      ; Draw 3 digits
         LDA $11A8       ; Evade
         JSR C304E0      ; Turn into text
         LDX #$7F7D      ; Text position
         JSR C304C0      ; Draw 3 digits
         LDA $11BB       ; Mag.Def
         JSR C304E0      ; Turn into text
         LDX #$7FFD      ; Text position
         JSR C304C0      ; Draw 3 digits
         LDA $11AA       ; MBlock
         JSR C304E0      ; Turn into text
         LDX #$887D      ; Text position
         JSR C304C0      ; Draw 3 digits
         LDY #$398F      ; Text position
         JSR C334CF      ; Draw actor name
         LDY #$399D      ; Text position
         JSR C334E5      ; Actor class...
         LDY #$39B1      ; Text position
         JSR C334E6      ; Draw held esper
         JSR C36102      ; Draw commands
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDX #C36096     ; Coords tbl ptr
         JSR C30C6C      ; Draw LV, HP, MP
         LDX $67         ; Actor's address
         LDA $0011,X     ; Experience LB
         STA $F1         ; Memorize it
         LDA $0012,X     ; Experience MB
         STA $F2         ; Memorize it
         LDA $0013,X     ; Experience HB
         STA $F3         ; Memorize it
         JSR C30582      ; Turn into text
         LDX #$7CD7      ; Text position
         JSR C304A3      ; Draw 8 digits
         JSR C360A0      ; Get needed exp
         JSR C30582      ; Turn into text
         LDX #$7DD7      ; Text position
         JSR C304A3      ; Draw 8 digits
         STZ $47         ; Ailments: Off
         JSR C311B0      ; Hide ail. icons
         JMP C3625B      ; Display status

; Tilemap pointers for stats in Status menu
C36096:  dw $3A27        ; Level
         dw $3A63        ; HP
         dw $3A6D        ; Max HP
         dw $3AA3        ; MP
         dw $3AAD        ; Max MP

; Calculate experience needed to level up
C360A0:  LDX $67         ; Actor's address
         TDC             ; ...
         LDA $0008,X     ; Level
         CMP #$63        ; 99?
         BEQ C360C3      ; Branch if so
         JSR C360CA      ; Get needed XP
         LDX $67         ; Actor's address
         SEC             ; Prepare SBC
         LDA $F1         ; Needed XP LB
         SBC $0011,X     ; Deduct XP LB
         STA $F1         ; Save changes
         REP #$20        ; 16-bit A
         LDA $F2         ; Needed XP HBs
         SBC $0012,X     ; Deduct XP HBs
         STA $F2         ; Save changes
         SEP #$20        ; 8-bit A
         RTS

; Fork: Zero experience needed
C360C3:  TDC             ; Clear A
         TAX             ; Clear X
         STX $F1         ; Needed XP LBs
         STZ $F3         ; Needed XP HB
         RTS

; Calculate total experience needed to level up
C360CA:  ASL A           ; Level x2
         STA $EB         ; Set counter
         TDC             ; Clear A
         TAX             ; 1st: Level 1
         STX $F1         ; Total LBs: 0
         STX $F3         ; Total HBs: 0
         STZ $EC         ; Level HB: 0
C360D5:  CLC             ; ...
         LDA $ED8220,X   ; Needed XP LB
         ADC $F1         ; Add total LB
         STA $F1         ; Set total LB
         INX             ; Index +1
         LDA $ED8220,X   ; Needed XP HB
         ADC $F2         ; Add total MB+C
         STA $F2         ; Set total MB
         TDC             ; Zero A
         ADC $F3         ; Add total HB+C
         STA $F3         ; Set total HB
         INX             ; Index +1
         CPX $EB         ; At current LV?
         BNE C360D5      ; Loop if not

; Fork: Octuple total to get true value
C360F1:  REP #$20        ; 16-bit A
         ASL $F1         ; Total LBs x2
         ROL $F3         ; HBs x2 + C
         ASL $F1         ; Total LBs x2
         ROL $F3         ; HBs x2 + C
         ASL $F1         ; Total LBs x2
         ROL $F3         ; HBs x2 + C
         SEP #$20        ; 8-bit A
         RTS

; Draw actor's command list in Status menu
C36102:  LDY #$7BF1      ; Tilemap ptr
         JSR C33519      ; Set pos/WRAM/Y
         JSR C35EE1      ; Draw command 1
         LDY #$7C71      ; Tilemap ptr
         JSR C33519      ; Set pos/WRAM/Y
         INY             ; Point to cmd 2
         JSR C35EE1      ; Draw command 2
         LDY #$7CF1      ; Tilemap ptr
         JSR C33519      ; Set pos/WRAM/Y
         INY             ; Point to cmd 2
         INY             ; Point to cmd 3
         JSR C35EE1      ; Draw command 3
         LDY #$7D71      ; Tilemap ptr
         JSR C33519      ; Set pos/WRAM/Y
         INY             ; Point to cmd 2
         INY             ; Point to cmd 3
         INY             ; Point to cmd 4
         JMP C35EE1      ; Draw command 4

; Handle battle command modifiers
C3612C:  LDA $0016,Y     ; Command
         CMP #$02        ; Magic?
         BNE C3613E      ; Branch if not
         PHY             ; Save index
         JSR C30D2B      ; Can use magic?
         BCS C3613D      ; Branch if so
         PLY             ; Actor's address
         LDA #$FF        ; Command: None
         RTS

; Fork: Morph
C3613D:  PLY             ; Actor's address
C3613E:  LDA $0016,Y     ; Command
         CMP #$03        ; Morph?
         BNE C3614F      ; Branch if not
         LDA $1DD1       ; Event flags
         BIT #$04        ; Unlocked Morph?
         BNE C3614F      ; Branch if so
         LDA #$FF        ; Command: None
         RTS

; Fork: Leap
C3614F:  LDA $0016,Y     ; Command
         CMP #$11        ; Leap?
         BNE C36160      ; Branch if not
         LDA $11E4       ; Veldt flags
         BIT #$04        ; Can show Leap?
         BNE C36160      ; Branch if so
         LDA #$FF        ; Command: None
         RTS

; Fork: Dance
C36160:  LDA $0016,Y     ; Command
         CMP #$13        ; Dance?
         BNE C3616F      ; Branch if not
         LDA $1D4C       ; Known Dances
         BNE C3616F      ; Branch if any
         LDA #$FF        ; Command: None
         RTS

; Fork: Relic effects
C3616F:  LDA $0016,Y     ; Command
         STA $E0         ; Memorize it
         TDC             ; Clear A
         TAX             ; 1st: Capture
         LDA $11D6       ; Relic effects
         AND #$7C        ; Cmd upgrades
         ASL A           ; Shift bits
C3617C:  ASL A           ; Got current?
         BCC C36189      ; Skip if not
         PHA             ; Save upgrades
         LDA.L C36198,X  ; Cmd to switch
         CMP $E0         ; Current cmd?
         BEQ C36192      ; Replace if so
         PLA             ; Cmd upgrades
C36189:  INX             ; Index +1
         CPX #$0005      ; Done Fight?
         BNE C3617C      ; Loop if not
         LDA $E0         ; Original cmd
         RTS

; Fork: Replace command
C36192:  PLA             ; Clean stack
         LDA.L C3619D,X  ; New command
         RTS

; Commands to upgrade
C36198:  db $05          ; Steal
         db $0F          ; Slot
         db $0D          ; Sketch
         db $02          ; Magic
         db $00          ; Fight

; Command upgrades
C3619D:  db $06          ; Capture
         db $18          ; GP Rain
         db $0E          ; Control
         db $17          ; X Magic
         db $16          ; Jump

; Replace portrait in Status menu after actor swap
C361A2:  TDC             ; Clear A
         LDA $60         ; Queue index
         TAX             ; Index it
         LDA #$FF        ; Null value
         STA $7E35C9,X   ; Hide old one

; Create portrait by upper-left corner
C361AC:  JSR C361DA      ; Queue OAM fn
         JMP C361E6      ; Init sprite

; Create portrait for Equip or Relic menu
C361B2:  JSR C361DA      ; Queue OAM fn
         PHB             ; Save DB
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         REP #$20        ; 16-bit A
         LDA #$00C8      ; X: 200
         STA $33CA,X     ; Set sprite's
         SEP #$20        ; 8-bit A
         TDC             ; ...
         LDA $28         ; Member slot
         TAY             ; Put in Y
         JSR C30ACC      ; Set anim ptr
         REP #$20        ; 16-bit A
         LDA #$0030      ; Y: 48
         STA $344A,X     ; Set sprite's
         SEP #$20        ; 8-bit A
         JSR C31206      ; Set pose timer
         PLB             ; Restore DB
         RTS

; Create portrait A
C361DA:  LDA #$03        ; Min slot: 24
         LDY #C30B12     ; C3/0B12
         JSR C31173      ; Queue OAM fn
         TXA             ; Queue index
         STA $60         ; Set sprite's
         RTS

; Place portrait by upper-left corner, set pose timer
C361E6:  PHB             ; Save DB
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         TDC             ; Clear A
         LDA $28         ; Member slot
         TAY             ; Put in Y
         JSR C30AF1      ; Set X position
         TDC             ; ...
         LDA $28         ; ...
         TAY             ; ...
         JSR C361FB      ; Set Y/ptr/timer
         PLB             ; Restore DB
         RTS

; Initialize variables for portrait by upper-left corner
C361FB:  JSR C30ACC      ; Load anim ptr
         REP #$20        ; 16-bit A
         LDA #$0038      ; Y: 56
         STA $344A,X     ; Set sprite's
         SEP #$20        ; 8-bit A
         JMP C31206      ; Set pose timer

; Set to condense BG3 text in Status menu
C3620B:  LDA #$02        ; 1Rx2B to PPU
         STA $4350       ; Set DMA mode
         LDA #$12        ; $2112
         STA $4351       ; To BG3 V-Scroll
         LDY #C3622A     ; C3/622A
         STY $4352       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4354       ; Set src HB
         LDA #$C3        ; ...
         STA $4357       ; Set indir HB
         LDA #$20        ; Channel: 5
         TSB $43         ; Queue HDMA-5
         RTS

; Text shifting table for the above
C3622A:  db $27,$00,$00  ; Status
         db $0C,$04,$00  ; Cmd choice A
         db $0C,$08,$00  ; Cmd choice B
         db $0C,$0C,$00  ; Cmd choice C
         db $0C,$10,$00  ; Cmd choice D
         db $0C,$14,$00  ; Command A
         db $0C,$18,$00  ; Command B
         db $0C,$1C,$00  ; Command C
         db $0C,$20,$00  ; Command D
         db $0C,$24,$00  ; Needed exp.
         db $0C,$28,$00  ; Bat.Pwr
         db $0C,$2C,$00  ; Defense
         db $0C,$30,$00  ; Evade
         db $0C,$34,$00  ; Mag.Def
         db $0C,$38,$00  ; MBlock
         db $0C,$3C,$00  ; Nothing
         db $00          ; End

; Display status effects in Status menu
C3625B:  LDY #$399D      ; Text position
         LDX #$2050      ; Icon position
         STX $E7         ; Set as current
         JSR C33519      ; Set text pos
         LDA $0014,Y     ; Wounded?
         BMI C362E7      ; Draw it if so
         AND #$70        ; Clear/Imp/Pet
         STA $E1         ; Memorize them
         LDA $0014,Y     ; Status effects
         AND #$07        ; Dark/Zom/Poison
         ASL A           ; Put in b1-b3
         STA $E2         ; Memorize them
         LDA $0015,Y     ; Status effects
         AND #$80        ; Isolate Float
         ORA $E1         ; Add Clear, etc.
         ORA $E2         ; Add Dark, etc.
         STA $E1         ; ...
         BEQ C362E1      ; Blank if none
         STZ $F1         ; GFX index LB: 0
         STZ $F2         ; GFX index HB: 0
         LDX #$0007      ; Status left: 7
C3628B:  PHX             ; Save counter
         ASL A           ; Got current?
         BCC C362D5      ; Skip if not
         PHA             ; Save status
         LDA #$03        ; Min slot: 24
         LDY #C37B42     ; C3/7B42
         JSR C31173      ; Queue icon OAM
         LDA #$01        ; Pans with BG1
         STA $7E364A,X   ; Set OBJ flags
         TDC             ; Anim mode: 0
         STA $7E3649,X   ; Set icon's
         TXY             ; Queue index
         LDX $F1         ; GFX index
         PHB             ; Save DB
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         REP #$20        ; 16-bit A
         LDA $D8EC25,X   ; Anim table ptr
         STA $32C9,Y     ; Set icon's
         SEP #$20        ; 8-bit A
         LDA $E7         ; X position
         STA $33CA,Y     ; Set icon's
         LDA $E8         ; Y position
         STA $344A,Y     ; Set icon's
         TDC             ; Clear A
         STA $33CB,Y     ; No use...
         STA $344B,Y     ; No use...
         LDA #$D8        ; Bank: D8
         STA $35CA,Y     ; Set ptr HB
         PLB             ; Restore DB
         CLC             ; Prepare ADC
         LDA #$0A        ; Modifier: +10
         ADC $E7         ; Add current X
         STA $E7         ; Set current X
         PLA             ; Status effects
C362D5:  INC $F1         ; GFX index +1
         INC $F1         ; GFX index +1
         PLX             ; Status left
         DEX             ; One less left
         BNE C3628B      ; Loop till last
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
C362E1:  JSR C36306      ; Load 8 spaces
         JMP C37FD9      ; Blank "Wounded"

; Fork: Draw "Wounded"
C362E7:  LDX #$9E8B      ; 7E/9E8B
         STX $2181       ; Set WRAM LBs
         LDX $00         ; Index: 0
C362EF:  LDA.L C3371B,X  ; Letter
         STA $2180       ; Add to string
         INX             ; Point to next
         CPX #$0008      ; Copied 8?
         BNE C362EF      ; Loop if not
         STZ $2180       ; End string
         LDA #$28        ; Palette 2
         STA $29         ; Color: Gray
         JMP C37FD9      ; Draw string

; Create blank string for erasing "Wounded"
C36306:  LDX #$9E8B      ; 7E/9E8B
         STX $2181       ; Set WRAM LBs
         LDX $00         ; Spaces: 0
         LDA #$FF        ; Space char
C36310:  STA $2180       ; Add to string
         INX             ; One more done
         CPX #$0008      ; Added 8?
         BNE C36310      ; Loop if not
         STZ $2180       ; End string
         RTS

; 42: Initialize Lineup's Status menu
C3631D:  JSR C3352F      ; Reset/Stop stuff
         LDA $0200       ; Menu number
         STA $22         ; Memorize it
         STZ $0200       ; Actor arrows: Off...
         STZ $25         ; Never read...
         LDA #$40        ; Channel: 6
         TRB $43         ; Halt HDMA-6...
         JSR C3620B      ; Set to shift text
         JSR C36354      ; Draw menu; portrait
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         LDA #$43        ; C3/633F
         STA $27         ; Queue: Sustain menu
         JMP C33541      ; BRT:1 + NMI

; 43: Sustain Lineup's Status menu
C3633F:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C36353      ; Exit if not
         JSR C30EA9      ; Sound: Cursor
         LDA $4C         ; Menu return cmd
         STA $27         ; Queue menu exit
         STZ $26         ; Next: Fade-out
         LDA $22         ; Former menu
         STA $0200       ; Set as current
C36353:  RTS

; Draw Lineup's Status menu, create portrait
C36354:  JSR C35D17      ; Draw windows
         JSR C35D3C      ; Draw blue text
         JSR C36379      ; Get actor address
         JSR C35FC2      ; Draw actor info
         JSR C35D77      ; Upload tilemaps
         JSR C361DA      ; Init portrait
         PHB             ; Save DB
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         TDC             ; Clear A
         LDA $28         ; Actor
         TAY             ; Index it
         JSR C3638E      ; Set portrait's X
         TDC             ; Clear A
         TAY             ; Portrait slot: 1
         JSR C361FB      ; Set Y/ptr/timer
         PLB             ; Restore DB
         RTS

; Load actor number and address for Lineup's Status menu
C36379:  TDC             ; Clear A
         LDA $C9         ; Actor
         STA $28         ; Memorize it
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C36969,X  ; Actor's address
         STA $67         ; Memorize it
         SEP #$20        ; 8-bit A
         TDC             ; ...
         LDA $C9         ; Actor
         RTS

; Set portrait's X position for Lineup's Status menu
C3638E:  LDA $1850,Y     ; Actor info
         BIT #$20        ; Back row?
         BEQ C3639C      ; Branch if not
         REP #$20        ; 16-bit A
         LDA #$001A      ; X: 26
         BRA C363A1      ; Skip 2 lines
C3639C:  REP #$20        ; 16-bit A
         LDA #$000E      ; X: 15
C363A1:  STA $33CA,X     ; Set sprite's
         SEP #$20        ; 8-bit A
         RTS

; 6A: Sustain shifted Status menu
C363A7:  JSR C36409      ; Handle D-Pad
         LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C363DA      ; Branch if not
         JSR C30EB2      ; Sound: Click
         STZ $0065       ; Edited slot HB
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         TAX             ; Index it
         LDA $7E9D8A,X   ; Chosen command
         STA $E0         ; Memorize it
         TDC             ; ...
         LDA $28         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         LDY $6D,X       ; Actor's address
         REP #$20        ; 16-bit A
         TYA             ; Move it to A
         CLC             ; Prepare ADC
         ADC $64         ; Add edited slot
         TAY             ; Index sum
         SEP #$20        ; 8-bit A
         LDA $E0         ; Chosen command
         STA $0016,Y     ; Assign to actor
         JSR C36102      ; Redraw commands
         BRA C363E3      ; Shift screen

; Fork: Handle B
C363DA:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C36402      ; Exit if not
         JSR C30EA9      ; Sound: Cursor
C363E3:  LDA #$01        ; Blinker: Off
         TRB $46         ; Set menu flag
         LDA #$06        ; Frames: 6
         STA $20         ; Set scroll timer
         LDY #$FFF4      ; Speed: -12
         STY $9C         ; Set scroll speed
         LDA #$0C        ; C3/21F5
         STA $27         ; Queue: Normal menu
         LDA #$65        ; C3/36E7
         STA $26         ; Next: Shift screen
         JSR C336FF      ; Load navig data
         LDA $5E         ; Old cursor row
         STA $4E         ; Set as current
         JSR C33708      ; Relocate cursor
C36402:  RTS

; Load navigation data for shifted Status menu
C36403:  LDY #C36412     ; C3/6412
         JMP C305FE      ; Load navig data

; Handle D-Pad for shifted Status menu
C36409:  JSR C3072D      ; Handle D-Pad
C3640C:  LDY #C36417     ; C3/6417
         JMP C30640      ; Relocate cursor

; Navigation data for shifted Status menu
C36412:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $10          ; 16 rows

; Cursor positions for shifted Status menu
C36417:  dw $10F0        ; Empty
         dw $1CF0        ; Command 1
         dw $28F0        ; Command 2
         dw $34F0        ; Command 3
         dw $40F0        ; Command 4
         dw $4CF0        ; Command 5
         dw $58F0        ; Command 6
         dw $64F0        ; Command 7
         dw $70F0        ; Command 8
         dw $7CF0        ; Command 9
         dw $88F0        ; Command 10
         dw $94F0        ; Command 11
         dw $A0F0        ; Command 12
         dw $ACF0        ; Command 13
         dw $B8F0        ; Command 14
         dw $C4F0        ; Command 15 (unused)

; Text pointers for Status menu
C36437:  dw C36497       ; Vigor
         dw C3649F       ; Stamina
         dw C364A9       ; Mag.Pwr
         dw C364B3       ; Evade %
         dw C364BD       ; MBlock%
         dw C364C7       ; ..
         dw C364CB       ; ..
         dw C364CF       ; ..
         dw C364D3       ; ..
         dw C364D7       ; ..
         dw C364DB       ; ..
         dw C364DF       ; ..
         dw C364E3       ; ..
         dw C364E7       ; ..
         dw C3646F       ; Status

; Text pointers for Status menu
C36455:  dw C36488       ; LV
         dw C3648D       ; HP
         dw C36492       ; MP

; Text pointers for Status menu
C3645B:  dw C36478       ; /
         dw C3647C       ; /
         dw C36480       ; %
         dw C36484       ; %

; Text pointers for Status menu
C36463:  dw C364EB       ; Speed
         dw C364F3       ; Bat.Pwr
         dw C364FD       ; Defense
         dw C36507       ; Mag.Def
         dw C36511       ; Your Exp:
         dw C3651D       ; For level up:

; Positioned text for Status menu
C3646F:  dw $78CD : db "Status",$00
C36478:  dw $3A6B : db "/",$00
C3647C:  dw $3AAB : db "/",$00
C36480:  dw $7F83 : db "%",$00
C36484:  dw $8883 : db "%",$00
C36488:  dw $3A1D : db "LV",$00
C3648D:  dw $3A5D : db "HP",$00
C36492:  dw $3A9D : db "MP",$00
C36497:  dw $7ECF : db "Vigor",$00
C3649F:  dw $7FCF : db "Stamina",$00
C364A9:  dw $884F : db "Mag.Pwr",$00
C364B3:  dw $7F69 : db "Evade %",$00
C364BD:  dw $8869 : db "MBlock%",$00
C364C7:  dw $7EDD : db !2dot,$00
C364CB:  dw $7F5D : db !2dot,$00
C364CF:  dw $7FDD : db !2dot,$00
C364D3:  dw $885D : db !2dot,$00
C364D7:  dw $7EFB : db !2dot,$00
C364DB:  dw $7F7B : db !2dot,$00
C364DF:  dw $7E7B : db !2dot,$00
C364E3:  dw $7FFB : db !2dot,$00
C364E7:  dw $887B : db !2dot,$00
C364EB:  dw $7F4F : db "Speed",$00
C364F3:  dw $7E69 : db "Bat.Pwr",$00
C364FD:  dw $7EE9 : db "Defense",$00
C36507:  dw $7FE9 : db "Mag.Def",$00
C36511:  dw $7C4D : db "Your Exp:",$00
C3651D:  dw $7D4D : db "For level up:",$00

; 5D: Initialize actor naming menu
C3652D:  JSR C3352F      ; Reset/Stop stuff
         LDY $0201       ; Actor's address
         STY $67         ; Memorize it
         JSR C36904      ; Reset BGs' X/Y
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         STZ $4A         ; Screen: 1st...
         JSR C36638      ; Load navig data
         JSR C36641      ; Relocate cursor
         JSR C307B0      ; Queue cursor OAM
         JSR C36705      ; Draw menu
         JSR C36621      ; Set arrow's column
         JSR C3683C      ; Set to shift text
         JSR C3678C      ; Get portrait colors
         JSR C36771      ; Upload portrait GFX
         JSR C366D8      ; Create portrait
         LDA #$02        ; Min slot: 16
         LDY #C368A3     ; C3/68A3
         JSR C31173      ; Queue arrow OAM
         LDA #$5F        ; C3/656C
         STA $27         ; Queue: Sustain menu
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         JMP C33541      ; BRT:1 + NMI

; 5F: Sustain actor naming menu
C3656C:  JSR C30EE9      ; Queue text upload
         JSR C3663E      ; Handle D-Pad
         JSR C3675B      ; Redraw actor name

; Fork: Handle Start
C36575:  LDA $09         ; No-autofire keys
         BIT #$10        ; Pushing Start?
         BEQ C3657E      ; Branch if not
         JMP C365C2      ; Validate name

; Fork: Handle A
C3657E:  LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C36595      ; Branch if not
         JSR C30EB2      ; Sound: Click
         TDC             ; Mode: Add
         JSR C365E8      ; Add letter
         LDA $28         ; Arrow's column
         CMP #$05        ; Rightmost?
         BEQ C36592      ; Exit if so
         INC A           ; Go right by 1
C36592:  STA $28         ; Save changes
         RTS

; Fork: Handle B
C36595:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C365C1      ; Exit if not
         JSR C30EC7      ; Sound: Delete
         LDA $28         ; Arrow's column
         BEQ C365C1      ; Exit if first
         CMP #$05        ; Rightmost?
         BNE C365B5      ; Branch if not
         JSR C3660F      ; Define Y
         LDA $0002,Y     ; Letter 6
         CMP #$FF        ; Blank?
         BEQ C365B5      ; Branch if so
         LDA #$FF        ; Mode: Delete V1
         JMP C365E8      ; Delete letter 6

; Fork: Delete non-sixth letter
C365B5:  LDA #$01        ; Mode: Delete V2
         JSR C365E8      ; Delete letter
         LDA $28         ; Arrow's column
         BEQ C365BF      ; ...
         DEC A           ; Go left by 1
C365BF:  STA $28         ; Save changes
C365C1:  RTS

; Validate entered actor name
C365C2:  LDY $67         ; Actor's address
         LDX $00         ; Letter count: 0
C365C6:  LDA $0002,Y     ; Letter
         CMP #$FF        ; Terminator?
         BNE C365DB      ; Valid if not
         INY             ; Letter index +1
         INX             ; Letter count +1
         CPX #$0006      ; Done 6 letters?
         BNE C365C6      ; Loop if not
         JSR C30EC0      ; Play buzzer
         JSR C3305D      ; Pixelate screen
         RTS             ; Exit
C365DB:  JSR C30EB2      ; Sound: Click
         STZ $0205       ; Never read...
         LDA #$FF        ; Null value
         STA $27         ; Queue menu exit
         STZ $26         ; Next: Fade-out
         RTS

; Add or remove letter from actor name
C365E8:  PHA             ; Save mode
         JSR C3660F      ; Define Y
         PLA             ; Deleting 6th?
         BMI C365FA      ; Branch if so
         BEQ C36600      ; Branch if adding
         LDA #$FF        ; Char: Terminator
         STA $0002,Y     ; ...
         STA $0001,Y     ; Clear last letter
         RTS

; Fork: Delete letter 6
C365FA:  LDA #$FF        ; Char: Terminator
         STA $0002,Y     ; Clear letter 6
         RTS

; Fork: Add selected letter
C36600:  TDC             ; Clear A
         LDA $4B         ; Selected slot
         CLC             ; Prepare ADC
         ADC $4A         ; For SFC...
         TAX             ; Index sum
         LDA $D8E8C8,X   ; Chosen letter
         STA $0002,Y     ; Add to name
         RTS

; Get index for overwritten letter in actor naming menu
C3660F:  LDY $67         ; Actor's address
         LDA $28         ; Arrow column
         STA $E7         ; Memorize it
         STZ $E8         ; Clear HB
         REP #$20        ; 16-bit A
         TYA             ; Actor's address
         CLC             ; Prepare ADC
         ADC $E7         ; Add column
         TAY             ; Put sum in Y
         SEP #$20        ; 8-bit A
         RTS

; Initialize arrow's column for actor naming menu
C36621:  LDY $67         ; Actor's address
         LDX $00         ; Column: 1st
C36625:  LDA $0002,Y     ; Current letter
         CMP #$FF        ; Terminator?
         BEQ C36634      ; Branch if so
         INY             ; Point to next
         INX             ; Arrow column +1
         CPX #$0006      ; Done 6 letters?
         BNE C36625      ; Loop if not
         DEX             ; Column: 6th
C36634:  TXA             ; Move column to A
         STA $28         ; Set arrow column
         RTS

; Load navigation data for actor naming menu
C36638:  LDY #C36647     ; C3/6647
         JMP C305FE      ; Load navig data

; Handle D-Pad for actor naming menu
C3663E:  JSR C3072D      ; Handle D-Pad
C36641:  LDY #C3664C     ; C3/664C
         JMP C30640      ; Relocate cursor

; Navigation data for actor naming menu
C36647:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $0A          ; 10 columns
         db $07          ; 7 rows

; Cursor positions for actor naming menu
C3664C:  dw $5838        ; A
         dw $5848        ; B
         dw $5858        ; C
         dw $5868        ; D
         dw $5878        ; E
         dw $5890        ; a
         dw $58A0        ; b
         dw $58B0        ; c
         dw $58C0        ; d
         dw $58D0        ; e
         dw $6838        ; F
         dw $6848        ; G
         dw $6858        ; H
         dw $6868        ; I
         dw $6878        ; J
         dw $6890        ; f
         dw $68A0        ; g
         dw $68B0        ; h
         dw $68C0        ; i
         dw $68D0        ; j
         dw $7838        ; K
         dw $7848        ; L
         dw $7858        ; M
         dw $7868        ; N
         dw $7878        ; O
         dw $7890        ; k
         dw $78A0        ; l
         dw $78B0        ; m
         dw $78C0        ; n
         dw $78D0        ; o
         dw $8838        ; P
         dw $8848        ; Q
         dw $8858        ; R
         dw $8868        ; S
         dw $8878        ; T
         dw $8890        ; p
         dw $88A0        ; q
         dw $88B0        ; r
         dw $88C0        ; s
         dw $88D0        ; t
         dw $9838        ; U
         dw $9848        ; V
         dw $9858        ; W
         dw $9868        ; X
         dw $9878        ; Y
         dw $9890        ; u
         dw $98A0        ; v
         dw $98B0        ; w
         dw $98C0        ; x
         dw $98D0        ; y
         dw $A838        ; Z
         dw $A848        ; !
         dw $A858        ; ?
         dw $A868        ; /
         dw $A878        ; :
         dw $A890        ; z
         dw $A8A0        ; ”
         dw $A8B0        ; ’
         dw $A8C0        ; -
         dw $A8D0        ; .
         dw $B838        ; 0
         dw $B848        ; 1
         dw $B858        ; 2
         dw $B868        ; 3
         dw $B878        ; 4
         dw $B890        ; 5
         dw $B8A0        ; 6
         dw $B8B0        ; 7
         dw $B8C0        ; 8
         dw $B8D0        ; 9

; Create portrait for actor naming menu
C366D8:  LDA #$03        ; Min slot: 24
         LDY #C30B12     ; C3/0B12
         JSR C31173      ; Queue OAM fn
         PHB             ; Save DB
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         REP #$20        ; 16-bit A
         LDA #C30B8C     ; Anim table ptr
         STA $32C9,X     ; Set sprite's
         LDA #$0010      ; X: 16
         STA $33CA,X     ; Set sprite's
         LDA #$0010      ; Y: 16
         STA $344A,X     ; Set sprite's
         SEP #$20        ; 8-bit A
         LDA #$C3        ; Bank: C3
         STA $35CA,X     ; Set ptr HB
         JSR C31206      ; Set pose timer
         PLB             ; Restore DB
         RTS

; Draw actor naming menu
C36705:  JSR C36A28      ; Clear BG2 map A
         LDY #C36765     ; C3/6765
         JSR C30341      ; Draw font window
         LDY #C36769     ; C3/6769
         JSR C30341      ; Draw face window
         LDY #C3676D     ; C3/676C
         JSR C30341      ; Draw top window
         LDY #C36761     ; C3/6761
         JSR C30341      ; Draw name window
         JSR C30E52      ; Upload windows
         JSR C36A15      ; Clear BG1 map A
         JSR C36A19      ; Clear BG1 map B
         JSR C36A1E      ; Clear BG1 map C
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDX #$395B      ; Tilemap ptr
         LDY #$E8C8      ; D8/E8C8
         STY $E7         ; Set src LBs
         LDA #$D8        ; Bank: D8
         STA $E9         ; Set src HB
         LDA #$07        ; Text rows: 7
         STA $E5         ; Set for options
         JSR C367BF      ; Draw options
         JSR C3675B      ; Draw actor name
         LDY #C368E3     ; Text pointer
         JSR C302F9      ; Draw "Please..."
         JSR C30E28      ; Upload BG1 A+B
         JSR C30E36      ; Upload BG1 B+C
         JSR C30E44      ; Upload BG1 C+D
         JSR C36A3C      ; Clear BG3 map A
         JMP C30E6E      ; Upload BG3 A+B

; Draw actor name for actor naming menu
C3675B:  LDY #$4229      ; Text position
         JMP C334CF      ; Draw actor name

; Window layout for actor naming menu
C36761:  dw $599B,$0212  ; 20x04 at $599B (Name)
C36765:  dw $5A57,$1116  ; 24x19 at $5A57 (Options)
C36769:  dw $588B,$0505  ; 07x07 at $588B (Portrait)
C3676D:  dw $5899,$0214  ; 22x04 at $5899 ("Please...")

; Upload portrait for actor naming menu
C36771:  LDY $67         ; Actor's address
         TDC             ; Clear A
         LDA $0001,Y     ; Graphics set
         REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAX             ; Index it
         LDA #$2600      ; $4C00
         STA $2116       ; Set VRAM ptr
         LDA.L C36F1B,X  ; GFX pointer
         TAX             ; Index it
         JSR C37000      ; Load portrait
         SEP #$20        ; 8-bit A
         RTS

; Load portrait colors for actor naming menu
C3678C:  LDA #$10        ; Colors: 16
         STA $E3         ; Set counter
         LDY $67         ; Actor's address
         TDC             ; Clear A
         LDA $0001,Y     ; Graphics set
         TAX             ; Index it
         LDA.L C36F00,X  ; Palette number
         REP #$20        ; 16-bit A
         ASL A           ; x2
         ASL A           ; x4
         ASL A           ; x8
         ASL A           ; x16
         ASL A           ; x32
         TAX             ; Index it
         LDY $00         ; RAM index: 0
C367A5:  REP #$20        ; 16-bit A
         PHX             ; Save ROM index
         LDA $ED5860,X   ; Portrait color
         TYX             ; RAM index
         STA $7E3149,X   ; To OBJ pal 0
         SEP #$20        ; 8-bit A
         PLX             ; ROM index
         INX             ; ROM index +1
         INX             ; ROM index +1
         INY             ; RAM index +1
         INY             ; RAM index +1
         DEC $E3         ; One less color
         BNE C367A5      ; Loop till last
         SEP #$20        ; 8-bit A
         RTS

; Draw options in actor naming menu
C367BF:  STX $EB         ; Set dst LBs
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set dst HB
         LDY $00         ; ROM index: 0
C367C7:  LDA #$0A        ; Columns: 10
         STA $E6         ; Set counter
         LDX $00         ; RAM index: 0
C367CD:  LDA [$E7],Y     ; Character
         STA $E0         ; Memorize it
         PHY             ; Save ROM index

; Fork: Character without diacritic
C367D2:  CMP #$53        ; Normal char?
         BCC C367DC      ; Branch if not
         LDA #$FF        ; Space char
         STA $E1         ; Set diacritic
         BRA C367FC      ; Update tilemap

; Fork: Character with handakuten (SFC)
C367DC:  CMP #$49        ; Bogus char?
         BCC C367ED      ; Branch if not
         LDA #$52        ; Mark: [°]
         STA $E1         ; Set diacritic
         LDA $E0         ; Letter number
         CLC             ; Prepare ADC
         ADC #$17        ; Get true one
         STA $E0         ; Save changes
         BRA C367FC      ; Update tilemap

; Fork: Character with dakuten (SFC)
C367ED:  CMP #$20        ; Roman range?
         BCC C367FC      ; Branch if not
         LDA #$51        ; Mark: ["]
         STA $E1         ; Set diacritic
         LDA $E0         ; Letter number
         CLC             ; Prepare ADC
         ADC #$40        ; Get true one
         STA $E0         ; Save changes

; Fork: Add character to tilemap
C367FC:  TXY             ; Base RAM index
         LDA $E1         ; Diacritic
         STA [$EB],Y     ; Add to tilemap
         INY             ; Index +1
         LDA $29         ; Palette, etc.
         STA [$EB],Y     ; Set attributes
         REP #$20        ; 16-bit A
         TXA             ; Base RAM index
         CLC             ; Prepare ADC
         ADC #$0040      ; Go 1 row down
         TAY             ; Index it
         SEP #$20        ; 8-bit A
         LDA $E0         ; Base character
         STA [$EB],Y     ; Add to tilemap
         INY             ; Index +1
         LDA $29         ; Palette, etc.
         STA [$EB],Y     ; Set attributes
         INX             ; RAM index +1
         INX             ; RAM index +1
         INX             ; RAM index +1
         INX             ; RAM index +1
         PLY             ; ROM index
         INY             ; ROM index +1
         LDA $E6         ; Columns left
         CMP #$06        ; At separator?
         BNE C36827      ; Branch if not
         INX             ; RAM index +1
         INX             ; RAM index +1
C36827:  DEC $E6         ; One less column
         BNE C367CD      ; Loop till last
         REP #$20        ; 16-bit A
         LDA $EB         ; Tilemap ptr
         CLC             ; Prepare ADC
         ADC #$0080      ; +2 rows down
         STA $EB         ; Save changes
         SEP #$20        ; 8-bit A
         DEC $E5         ; One less row
         BNE C367C7      ; Loop till last
         RTS

; Set to condense text in actor naming menu
C3683C:  LDX $00         ; Index: 0
C3683E:  LDA.L C36896,X  ; BG1 V-Pan data
         STA $7E9BC9,X   ; Save in RAM
         INX             ; Index +1
         CPX #$000D      ; End of table?
         BNE C3683E      ; Loop if not
         LDA #$02        ; 1Rx2B to PPU
         STA $4350       ; Set CH5 mode
         LDA #$0E        ; $210E
         STA $4351       ; To BG1 V-Scroll
         LDY #$9BC9      ; 7E/9BC9
         STY $4352       ; Set CH5 src LBs
         LDA #$7E        ; Bank: 7E
         STA $4354       ; Set CH5 src HB
         LDA #$7E        ; ...
         STA $4357       ; Set indir HB
         LDA #$20        ; Channel: 5
         TSB $43         ; Queue HDMA-5
         LDA #$02        ; 1Rx2B to PPU
         STA $4360       ; Set CH6 mode
         LDA #$0D        ; $210D
         STA $4361       ; To BG1 H-Scroll
         LDY #C36889     ; C3/6889
         STY $4362       ; Set CH6 src LBs
         LDA #$C3        ; Bank: C3
         STA $4364       ; Set CH6 src HB
         LDA #$C3        ; ...
         STA $4367       ; Set indir HB
         LDA #$40        ; Channel: 6
         TSB $43         ; Queue HDMA-6
         RTS

; BG1 H-Shift table for the above (merges tilemaps)
C36889:  db $47,$00,$01  ; Title, name
         db $50,$00,$00  ; Upper chars
         db $50,$00,$00  ; Lower chars
         db $10,$00,$01  ; Blank area
         db $00          ; End

; BG1 V-Shift table for the above (condenses text)
C36896:  db $47,$00,$00  ; Title, name
         db $50,$D0,$FF  ; Upper chars
         db $50,$D0,$FF  ; Lower chars
         db $10,$00,$00  ; Blank area
         db $00          ; End

; Update arrow in actor naming menu
C368A3:  TAX             ; Index mode
         JMP (C368A7,X)  ; Handle mode

; Jump table for the above
C368A7:  dw C368AB       ; Initialize arrow
         dw C368CB       ; Sustain arrow

; Mode 0: Initialize arrow
C368AB:  LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         LDA #C3B452     ; Anim table ptr
         STA $32C9,X     ; Set sprite's
         LDA #$0040      ; Y: 64
         STA $344A,X     ; Set sprite's
         SEP #$20        ; 8-bit A
         STZ $33CB,X     ; No use...
         LDA #$C3        ; Bank: C3
         STA $35CA,X     ; Set ptr HB
         JSR C31206      ; Set pose timer
         INC $3649,X     ; Mode +1

; Mode 1: Sustain arrow
C368CB:  LDY $2D         ; Queue index
         TDC             ; Clear A
         LDA $28         ; Arrow's slot
         TAX             ; Index it
         LDA.L C368DD,X  ; X position
         STA $33CA,Y     ; Set sprite's
         JSR C31221      ; Define OAM
         SEC             ; Set to requeue
         RTS

; Arrow's X positions in actor naming menu
C368DD:  db $78          ; Letter 1
         db $80          ; Letter 2
         db $88          ; Letter 3
         db $90          ; Letter 4
         db $98          ; Letter 5
         db $A0          ; Letter 6

; Positioned text for actor naming menu
C368E3:  dw $411B : db "Please enter a name.", $00

; Reset menu or ending variables
C368FA:  JSL $D4CDF3     ; Reset many vars
         JSR C36904      ; Reset BGs' X/Y
         JMP C3A796      ; Clear VWF GFX

; Reset BG positions
C36904:  LDY $00         ; Clear Y
         STY $35         ; BG1 X-Loc: 0
         STY $39         ; BG2 X-Loc: 0
         STY $3D         ; BG3 X-Loc: 0
         STY $37         ; BG1 Y-Loc: 0
         STY $3B         ; BG2 Y-Loc: 0
         STY $3F         ; BG3 Y-Loc: 0
         STY $41         ; List V-Spd: 0
         RTS

; Get party info from SRAM block
C36915:  JSL $D4CA00     ; Clear all info
         TDC             ; Clear A
         TAX             ; 1st: Terra
         TXY             ; ...
C3691C:  LDA $1850,X     ; Party info
         AND #$40        ; Object's off?
         BEQ C36941      ; Skip if so
         LDA $1850,X     ; Party info
         AND #$07        ; Get party
         CMP $1A6D       ; Active party?
         BNE C36941      ; Skip if not
         LDA $1850,X     ; Party info
         PHA             ; Memorize it
         AND #$18        ; Roster slot
         STA $E0         ; ...
         LSR A           ; Put in b2-b3
         LSR A           ; Put in b1-b2
         LSR A           ; Now 0-3
         TAY             ; Index it
         PLA             ; Party info
         STA $0075,Y     ; Set member's
         TXA             ; Actor slot
         STA $0069,Y     ; Set member's
C36941:  INX             ; Actor slot +1
         CPX #$0010      ; Done 16 chars?
         BNE C3691C      ; Loop if not
         LDY $00         ; 1st: Member 1
C36949:  TDC             ; Clear A
         LDA $0069,Y     ; Actor
         CMP #$FF        ; Empty slot?
         BEQ C36962      ; Skip if so
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C36969,X  ; Actor's address
         PHA             ; Memorize it
         TYA             ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         PLA             ; SRAM address
         STA $6D,X       ; Set member's
         SEP #$20        ; 8-bit A
C36962:  INY             ; Member slot +1
         CPY #$0004      ; Done 4 slots?
         BNE C36949      ; Loop if not
         RTS

; SRAM block addresses for actor data
C36969:  dw $1600        ; 00: Terra
         dw $1625        ; 01: Locke
         dw $164A        ; 02: Cyan
         dw $166F        ; 03: Shadow
         dw $1694        ; 04: Edgar
         dw $16B9        ; 05: Sabin
         dw $16DE        ; 06: Celes
         dw $1703        ; 07: Strago
         dw $1728        ; 08: Relm
         dw $174D        ; 09: Setzer
         dw $1772        ; 0A: Mog
         dw $1797        ; 0B: Gau
         dw $17BC        ; 0C: Gogo
         dw $17E1        ; 0D: Umaro
         dw $1806        ; 0E: Guest 1
         dw $182B        ; 0F: Guest 2

; Copy party info to SRAM block
C36989:  TDC             ; Clear A
         TAX             ; 1st: Member 1
         TAY             ; ...
C3698C:  LDA $69,X       ; Actor in slot
         BMI C369A2      ; Skip if nobody
         TAY             ; Index it
         LDA $75,X       ; Party info
         AND #$E7        ; Clear roster slot
         STA $E0         ; Memorize info
         TDC             ; ...
         TXA             ; Member slot
         ASL A           ; Put in b1-b2
         ASL A           ; Put in b2-b3
         ASL A           ; Put in b3-b4
         CLC             ; ...
         ADC $E0         ; Add saved info
         STA $1850,Y     ; Put in SRAM area
C369A2:  INX             ; Member slot +1
         CPX #$0004      ; Done 4 slots?
         BNE C3698C      ; Loop if not
         RTS

; Memorize current party (useless)
C369A9:  REP #$20        ; 16-bit A
         LDA $69         ; Members 1 and 2
         STA $7EAA89     ; Memorize them
         LDA $6B         ; Members 3 and 4
         STA $7EAA8B     ; Memorize them
         SEP #$20        ; 8-bit A
         RTS

; Draw multiple strings using consecutive pointers
C369BA:  STX $F1         ; Set ptrs loc
         STY $EF         ; Set counter
         LDA #$C3        ; Bank: C3
         STA $F3         ; Set loc HB
         LDY $00         ; Index: 0
C369C4:  REP #$20        ; 16-bit A
         LDA [$F1],Y     ; Text pointer
         STA $E7         ; Set src LBs
         PHY             ; Save index
         SEP #$20        ; 8-bit A
         LDA #$C3        ; Bank: C3
         STA $E9         ; Set src HB
         JSR C302FF      ; Draw string
         PLY             ; String index
         INY             ; Index +1
         INY             ; Index +1
         CPY $EF         ; None left?
         BNE C369C4      ; Loop if not
         RTS

; Set Window 1 positions per scanline
C369DC:  LDA #$01        ; 2Rx1B to PPU
         STA $4320       ; Set CH2 mode
         LDA #$26        ; $2126, $2127
         STA $4321       ; To Win 1 L+R
         LDY #C369FB     ; C3/69FB
         STY $4322       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4324       ; Set src HB
         LDA #$C3        ; ...
         STA $4327       ; Set indir HB
         LDA #$04        ; Channel: 2
         TSB $43         ; Queue HDMA-2
         RTS

; Window 1 positions per scanline
C369FB:  db $07,$FF,$00  ; No range
         db $78,$08,$F7  ; 8, 247
         db $58,$08,$F7  ; 8, 247
         db $08,$FF,$00  ; No range
         db $00          ; End

; Set global Window 1 positions
C36A08:  LDA #$04        ; Channel: 2
         TRB $43         ; Halt Win1 HDMA
         STZ $2126       ; Win1-L: 0
         LDA #$FF        ; Win1-R: 255
         STA $2127       ; Set register
         RTS

; Clear BG1 tilemap A
C36A15:  LDX $00         ; 7E/3849
         BRA C36A4E      ; Clear map

; Clear BG1 tilemap B
C36A19:  LDX #$0800      ; 7E/4049
         BRA C36A4E      ; Clear map

; Clear BG1 tilemap C
C36A1E:  LDX #$1000      ; 7E/4849
         BRA C36A4E      ; Clear map

; Clear BG1 tilemap D
C36A23:  LDX #$1800      ; 7E/5049
         BRA C36A4E      ; Clear map

; Clear BG2 tilemap A
C36A28:  LDX #$2000      ; 7E/5849
         BRA C36A4E      ; Clear map

; Clear BG2 tilemap B
C36A2D:  LDX #$2800      ; 7E/6049
         BRA C36A4E      ; Clear map

; Clear BG2 tilemap C
C36A32:  LDX #$3000      ; 7E/6849
         BRA C36A4E      ; Clear map

; Clear BG2 tilemap D (unused)
C36A37:  LDX #$3800      ; 7E/7049
         BRA C36A4E      ; Clear map

; Clear BG3 tilemap A
C36A3C:  LDX #$4000      ; 7E/7849
         BRA C36A4E      ; Clear map

; Clear BG3 tilemap B
C36A41:  LDX #$4800      ; 7E/8049
         BRA C36A4E      ; Clear map

; Clear BG3 tilemap C
C36A46:  LDX #$5000      ; 7E/8849
         BRA C36A4E      ; Clear map

; Clear BG3 tilemap D
C36A4B:  LDX #$5800      ; 7E/9049
C36A4E:  REP #$20        ; 16-bit A
         TDC             ; Clear A
         LDY #$0200      ; Tiles: 1024
C36A54:  STA $7E3849,X   ; Clear tile
         INX             ; Index +1
         INX             ; Index +1
         STA $7E3849,X   ; Clear tile
         INX             ; Index +1
         INX             ; Index +1
         DEY             ; 2 less tiles
         BNE C36A54      ; Loop till 0
         SEP #$20        ; 8-bit A
         RTS

; Load graphics, colors, enemy, and prize for Colosseum matchup
C36A66:  JSR C37010      ; ...
         JSR C36B13      ; BG3 font GFX
         JSR C36BE8      ; Font colors
         JSR C36C09      ; ...
         JSR C36E67      ; Cursor/VS GFX
         JSR C36CC7      ; Actor colors
         JSR C36C84      ; Cursor/VS colors
         JSR C36E82      ; ...
         JSR C36CE9      ; Actor sprites
         JSR C3AF46      ; Prize/enemy data
         JMP C3B34B      ; Arena

; Load non-skin graphics and colors for menu
C36A87:  TDC             ; Clear A
         LDA $0200       ; Menu
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C36A90,X)  ; Load data

; Jump table for the above
C36A90:  dw C36AE9       ; Main menu
         dw C36B04       ; Actor naming
         dw C36AE9       ; Load menu
         dw C36ACE       ; Shop
         dw C36AB0       ; Lineup
         dw C36AB0       ; Bogus...
         dw C36AA4       ; SwdTech naming
         dw C36AE9       ; Colosseum
         dw C36AB0       ; Final battle lineup
         dw C36AB0       ; Bogus...

; Load graphics and colors for SwdTech naming menu (SFC)
C36AA4:  JSR C36B37      ; BG1 font GFX
         JSR C36BE8      ; Font colors
         JSR C36E67      ; Cursor/arrow GFX
         JMP C36C84      ; Their colors

; Load graphics and colors for Lineup or final battle menu
C36AB0:  JSR C37010      ; Blank portrait
         JSR C36B13      ; BG3 font GFX
         JSR C36B37      ; BG1 font GFX
         JSR C36BE8      ; Font colors
         JSR C36C09      ; Portrait colors...
         JSR C36E67      ; Cursor/icon GFX
         JSR C36CC7      ; Actor colors
         JSR C36C84      ; Cursor/icon pals
         JSR C36E82      ; Portrait GFX...
         JMP C36CE9      ; Actor sprites

; Load graphics and colors for shop menu
C36ACE:  JSR C36B13      ; BG3 font GFX
         JSR C36B37      ; BG1 font GFX
         JSR C36BE8      ; Font colors
         JSR C36C09      ; Portrait colors...
         JSR C36E67      ; Cursor/icon GFX
         JSR C36CC7      ; Actor colors
         JSR C36C84      ; Cursor/icon pals
         JSR C36E82      ; Portrait GFX...
         JMP C36D79      ; Actor sprites

; Load graphics and colors for Load, Main, or Colosseum menu
C36AE9:  JSR C36B13      ; BG3 font GFX
         JSR C36B37      ; BG1 font GFX
         JSR C36BE8      ; Font colors
         JSR C36E67      ; Cursor/icon GFX
         JSR C36E82      ; Portrait GFX
         JSR C36C09      ; Portrait colors
         JSR C36CE9      ; Actor sprites
         JSR C36C84      ; Cursor/icon pals
         JMP C36C60      ; Grayscale pal

; Load graphics and colors for actor naming menu
C36B04:  JSR C36B13      ; Blank BG tile
         JSR C36B37      ; BG1 font GFX
         JSR C36BE8      ; Font colors
         JSR C36E67      ; Cursor GFX
         JMP C36C84      ; Cursor colors

; Upload BG3 font graphics and erase VWF description
C36B13:  REP #$20        ; 16-bit A
         LDY #$6000      ; $C000
         STY $2116       ; Set VRAM ptr
         LDX $00         ; Index: 0
C36B1D:  LDA $C47FC0,X   ; Font graphics
         STA $2118       ; Save in VRAM
         INX             ; Index +1
         INX             ; Index +1
         CPX #$1000      ; 256th tile?
         BNE C36B1D      ; Loop if not
C36B2B:  STA $2118       ; Clear desc GFX
         INX             ; Index +1
         CPX #$1400      ; 128th tile?
         BNE C36B2B      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Upload BG1 font graphics
C36B37:  LDY #$5000      ; $A000
         STY $2116       ; Set VRAM ptr
         REP #$20        ; 16-bit A
         TDC             ; Clear A
         TAX             ; Index: 0
C36B41:  LDY #$0008      ; 8-px rows: 8
C36B44:  LDA.L C36B9C,X  ; Square GFX
         STA $2118       ; Save in VRAM
         DEY             ; One less row
         BNE C36B44      ; Loop till last
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0020      ; Done 8 tiles?
         BNE C36B41      ; Loop if not
         LDX $00         ; Index: 0
C36B57:  LDY #$0008      ; 8-px rows: 8
C36B5A:  LDA $C48040,X   ; Font GFX row
         STA $2118       ; Save in VRAM
         INX             ; Index +1
         INX             ; Index +1
         DEY             ; One less row
         BNE C36B5A      ; Loop till last
         STZ $2118       ; Planes 1C, 1D
         STZ $2118       ; Planes 2C, 2D
         STZ $2118       ; Planes 3C, 3D
         STZ $2118       ; Planes 4C, 4D
         STZ $2118       ; Planes 5C, 5D
         STZ $2118       ; Planes 6C, 6D
         STZ $2118       ; Planes 7C, 7D
         STZ $2118       ; Planes 8C, 8D
         CPX #$0F80      ; 248th tile?
         BNE C36B57      ; Loop if not
         LDY #$7800      ; $F000
         STY $2116       ; Set VRAM ptr
         LDX $00         ; Index: 0
C36B8B:  LDA $ED0000,X   ; Skin GFX...
         STA $2118       ; Save in VRAM
         INX             ; Index +1
         INX             ; Index +1
         CPX #$1000      ; Done 8 skins?
         BNE C36B8B      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Square BG1 tiles, encoded as a single row
C36B9C:  dw $0000,$0000  ; Blank tile
         dw $00FF,$0000  ; Config: Palette color 1
         dw $FF00,$0000  ; Config: Palette color 2
         dw $FFFF,$0000  ; Config: Palette color 3
         dw $0000,$00FF  ; Config: Palette color 4
         dw $00FF,$00FF  ; Config: Palette color 5
         dw $FF00,$00FF  ; Config: Palette color 6
         dw $FFFF,$00FF  ; Config: Palette color 7

; Reset all skin colors
C36BBC:  LDX #$0008      ; Skins left: 8
         STX $E7         ; Set counter
         LDX #$0000      ; ROM index: 0
         TXY             ; RAM index: 0
         REP #$20        ; 16-bit A
C36BC7:  LDA #$0007      ; Colors left: 7
         STA $E9         ; Set counter
C36BCC:  LDA $ED1C02,X   ; Default color
         STA $1D57,Y     ; Save in options
         INX             ; ROM index +1
         INX             ; ROM index +1
         INY             ; RAM index +1
         INY             ; RAM index +1
         DEC $E9         ; One less color
         BNE C36BCC      ; Loop till last
         TXA             ; ROM index
         CLC             ; Prepare ADC
         ADC #$0012      ; Reach next skin
         TAX             ; Reindex it
         DEC $E7         ; One less skin
         BNE C36BC7      ; Loop till last
         SEP #$20        ; 8-bit A
         RTS

; Load font and black background's colors
C36BE8:  LDX $00         ; Color index: 0
         TXA             ; CGRAM: $0000
         STA $2121       ; To BG color 0
C36BEE:  REP #$20        ; 16-bit A
         LDA $D8E800,X   ; BG color
         STA $7E3049,X   ; Save in RAM
         SEP #$20        ; 8-bit A
         STA $2122       ; Put LB in CGRAM
         XBA             ; Switch to HB
         STA $2122       ; Put HB in CGRAM
         INX             ; Index +1
         INX             ; Index +1
         CPX #$00A0      ; Done 80 colors?
         BNE C36BEE      ; Loop if not
         RTS

; Load portrait colors for entire party
C36C09:  LDX $00         ; Member index: 0
         TXY             ; Dest index: 0
C36C0C:  REP #$20        ; 16-bit A
         LDA $6D,X       ; Actor data index
         PHX             ; Save member index
         PHY             ; Save dest index
         TAY             ; Actor data index
         TDC             ; Clear A
         SEP #$20        ; 8-bit A
         LDA #$10        ; Colors: 16
         STA $E3         ; Set counter
         LDA $0014,Y     ; Status
         AND #$20        ; Imp?
         BEQ C36C25      ; Branch if not
         LDA #$0F        ; Use Imp data
         BRA C36C30      ; Ignore actor
C36C25:  TDC             ; ...
         LDA $0000,Y     ; Actor
         CMP #$01        ; Locke?
         BEQ C36C30      ; Branch if so
         LDA $0001,Y     ; Graphics set
C36C30:  TAX             ; Index it
         LDA.L C36F00,X  ; Palette number
         REP #$20        ; 16-bit A
         ASL A           ; x2
         ASL A           ; x4
         ASL A           ; x8
         ASL A           ; x16
         ASL A           ; x32
         TAX             ; Index it
         PLY             ; RAM index
C36C3E:  REP #$20        ; 16-bit A
         PHX             ; Save ROM index
         LDA $ED5860,X   ; Portrait color
         TYX             ; RAM index
         STA $7E3149,X   ; Set color
         SEP #$20        ; 8-bit A
         PLX             ; ROM index
         INX             ; ROM index +1
         INX             ; ROM index +1
         INY             ; RAM index +1
         INY             ; RAM index +1
         DEC $E3         ; One less color
         BNE C36C3E      ; Loop till last
         PLX             ; Member index
         INX             ; Member index +1
         INX             ; Member index +1
         CPX #$0008      ; Done 4 members?
         BNE C36C0C      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Load grayscale actor palette
C36C60:  LDA #$90        ; Object color 16
         STA $2121       ; CGRAM: $0120
         LDX $00         ; Color index: 0
C36C67:  REP #$20        ; 16-bit A
         LDA $D8E8A0,X   ; Grayscale color
         STA $7E3169,X   ; To OBJ pal 1
         SEP #$20        ; 8-bit A
         STA $2122       ; Put LB in CGRAM
         XBA             ; Switch to HB
         STA $2122       ; Put HB in CGRAM
         INY             ; ...
         INY             ; ...
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0020      ; Done 16 colors?
         BNE C36C67      ; Loop if not
         RTS

; Load cursor, arrow, and icon colors
C36C84:  LDX $00         ; Color index: 0
         LDA #$EC        ; Object color 108
         STA $2121       ; CGRAM: $01D8
C36C8B:  REP #$20        ; 16-bit A
         LDA $D8E8C0,X   ; Status icon color
         STA $7E3221,X   ; Save in RAM
         SEP #$20        ; 8-bit A
         STA $2122       ; Put LB in CGRAM
         XBA             ; Switch to HB
         STA $2122       ; Put HB in CGRAM
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0008      ; Done 4 colors?
         BNE C36C8B      ; Loop if not
         LDX $00         ; Color index: 0
         LDA #$FC        ; Object color 124
         STA $2121       ; CGRAM: $01F8
C36CAC:  REP #$20        ; 16-bit A
         LDA $D8E8B8,X   ; Cursor, etc. color
         STA $7E3241,X   ; Save in RAM
         SEP #$20        ; 8-bit A
         STA $2122       ; Put LB in CGRAM
         XBA             ; Switch to HB
         STA $2122       ; Put HB in CGRAM
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0008      ; Done 4 colors?
         BNE C36CAC      ; Loop if not
         RTS

; Load actor sprite palettes
C36CC7:  LDX $00         ; Color index: 0
         LDA #$A0        ; Object color 32
         STA $2121       ; CGRAM: $0140
C36CCE:  REP #$20        ; 16-bit A
         LDA $ED6300,X   ; Sprite color
         STA $7E3189,X   ; Save in RAM
         SEP #$20        ; 8-bit A
         STA $2122       ; Put LB in CGRAM
         XBA             ; Switch to HB
         STA $2122       ; Put HB in CGRAM
         INX             ; Index +1
         INX             ; Index +1
         CPX #$00C0      ; Done 96 colors?
         BNE C36CCE      ; Loop if not
         RTS

; Upload actor sprite graphics (one pose)
C36CE9:  TDC             ; Clear A
         TAX             ; OBJ index: 0
C36CEB:  PHX             ; Save index
         REP #$20        ; 16-bit A
         LDA $CFF8E5,X   ; VRAM pointer
         STA $F3         ; Memorize it
         TXA             ; Sprite index
         ASL A           ; Double it
         TAX             ; Index it
         LDA $CFF913,X   ; GFX adr LBs
         STA $E7         ; Memorize it
         LDA $CFF911,X   ; GFX adr HBs
         STA $E9         ; Memorize it
         LDX $00         ; Ptr index: 0

; Fork: Head and torso
C36D05:  LDA $CFF8DF,X   ; Tile rel ptr
         STA $EF         ; Memorize it
         JSR C36D44      ; Load 2 tiles
         LDA $F3         ; VRAM pointer
         CLC             ; Prepare ADC
         ADC #$0100      ; Go 1 row down
         STA $F3         ; Save changes
         INX             ; Ptr index +1
         INX             ; Ptr index +1
         CPX #$0004      ; Done 2 rows?
         BNE C36D05      ; Loop if not

; Fork: Legs
C36D1D:  LDA $F3         ; VRAM pointer
         SEC             ; Prepare SBC
         SBC #$01E0      ; Row -2, col +2
         STA $F3         ; Save changes
         LDA $CFF8DF,X   ; Tile rel ptr
         STA $EF         ; Memorize it
         JSR C36D44      ; Load leg GFX

; Fork: Blank row
C36D2E:  LDA $F3         ; VRAM pointer
         CLC             ; Prepare ADC
         ADC #$0100      ; Go 1 row down
         STA $F3         ; Save changes
         JSR C36D67      ; Blank 4th row

; Fork: Handle next sprite
C36D39:  PLX             ; Sprite index
         INX             ; Index +1
         INX             ; Index +1
         CPX #$002C      ; 22th sprite?
         BNE C36CEB      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Upload both tiles in current row of actor sprite
C36D44:  CLC             ; Prepare ADC
         LDA $EF         ; Tile rel pointer
         ADC $E7         ; Add base adr LBs
         STA $EB         ; Set src LBs
         TDC             ; Zero A
         ADC $E9         ; Add adr HBs + C
         STA $ED         ; Set source HBs
         LDY $F3         ; VRAM pointer
         STY $2116       ; Set destination
         JMP C36D58      ; ...
C36D58:  LDY $00         ; Index: 0
C36D5A:  LDA [$EB],Y     ; Tile graphics
         STA $2118       ; Save in VRAM
         INY             ; Index +1
         INY             ; Index +1
         CPY #$0040      ; Done 2 tiles?
         BNE C36D5A      ; Loop if not
         RTS

; Blank both tiles under actor's feet
C36D67:  LDY $F3         ; VRAM pointer
         STY $2116       ; Set destination
         LDA #$0020      ; Tiles: 2
         STA $E7         ; Set counter
C36D71:  STZ $2118       ; 8 px, 2 planes
         DEC $E7         ; Counter -1
         BNE C36D71      ; Loop till zero
         RTS

; Upload actor sprites for shop
C36D79:  LDY #$3000      ; $6000
         STY $2116       ; Set VRAM ptr
         STZ $E3         ; Actor slot: 1

; Fork: Load both poses for two actors
C36D81:  LDY $00         ; Tile slot: 1
C36D83:  SEP #$20        ; 8-bit A
         TDC             ; Clear A
         TYX             ; Tile slot
         LDA.L C36E07,X  ; GFX ptr index
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C36E27,X  ; Tile's GFX ptr
         CMP #$FFFF      ; Blank tile?
         BEQ C36DEA      ; Blank if so
         PHA             ; Save pointer
         LDA #$16A0      ; GFX struct size
         SEP #$20        ; 8-bit A
         STA $211B       ; Set matrix A LB
         XBA             ; Struct size HB
         STA $211B       ; Set matrix A HB
         LDA $E3         ; Actor A's slot
         STA $211C       ; Set matrix B
         STA $211C       ; ...
         REP #$20        ; 16-bit A
         PLA             ; Tile GFX ptr
         CLC             ; Prepare ADC
         ADC $2134       ; Add product LBs
         STA $EB         ; Set source LBs
         SEP #$20        ; 8-bit A
         LDA $2136       ; Product HB
         ADC #$D5        ; Add base bank
         STA $ED         ; Set source HB
         REP #$21        ; ...
         LDA $EB         ; ...
         ADC #$0000      ; ...
         STA $EB         ; ...
         SEP #$20        ; ...
         LDA $ED         ; ...
         ADC #$00        ; ...
         STA $ED         ; ...
         REP #$20        ; 16-bit A
         PHY             ; Save tile slot
         JSR C36DF8      ; Load tile's GFX
         PLY             ; Tile slot
C36DD7:  INY             ; Tile slot +1
         CPY #$0020      ; Done 32 tiles?
         BNE C36D83      ; Loop if not

; Fork: Handle next two actors
C36DDD:  SEP #$20        ; 8-bit A
         INC $E3         ; Actor slot +1
         INC $E3         ; Actor slot +1
         LDA $E3         ; Actor slot
         CMP #$10        ; Handled 16?
         BNE C36D81      ; Loop if not
         RTS

; Fork: Create a blank tile
C36DEA:  LDA #$0010      ; Rows: 8
         STA $E7         ; Set counter
C36DEF:  STZ $2118       ; 8 px, 2 planes
         DEC $E7         ; Counter -1
         BNE C36DEF      ; Loop till zero
         BRA C36DD7      ; Do next tile

; Upload current actor sprite tile for shop
C36DF8:  LDY $00         ; Index: 0
C36DFA:  LDA [$EB],Y     ; 8 px, 2 planes
         STA $2118       ; Save in VRAM
         INY             ; Index +1
         INY             ; Index +1
         CPY #$0020      ; Done 8 rows?
         BNE C36DFA      ; Loop if not
         RTS

; Indices for loading tiles from two shop actors
C36E07:  db $00          ; Actor1 X1,Y1 (hands down)
         db $01          ; Actor1 X1,Y2 (hands down)
         db $04          ; Actor1 X3,Y1 (hands down)
         db $05          ; Actor1 X3,Y2 (hands down)
         db $08          ; Actor1 X1,Y1 (hands up)
         db $09          ; Actor1 X1,Y2 (hands up)
         db $0C          ; Actor1 X3,Y1 (hands up)
         db $0D          ; Actor1 X3,Y2 (hands up)
         db $10          ; Actor2 X1,Y1 (hands down)
         db $11          ; Actor2 X1,Y2 (hands down)
         db $14          ; Actor2 X3,Y1 (hands down)
         db $15          ; Actor2 X3,Y2 (hands down)
         db $18          ; Actor2 X1,Y1 (hands up)
         db $19          ; Actor2 X1,Y2 (hands up)
         db $1C          ; Actor2 X3,Y1 (hands up)
         db $1D          ; Actor2 X3,Y2 (hands up)
         db $02          ; Actor1 X2,Y1 (hands down)
         db $03          ; Actor1 X2,Y2 (hands down)
         db $06          ; Actor1 X4,Y1 (hands down)
         db $07          ; Actor1 X4,Y2 (hands down)
         db $0A          ; Actor1 X2,Y1 (hands up)
         db $0B          ; Actor1 X2,Y2 (hands up)
         db $0E          ; Actor1 X4,Y1 (hands up)
         db $0F          ; Actor1 X4,Y2 (hands up)
         db $12          ; Actor2 X2,Y1 (hands down)
         db $13          ; Actor2 X2,Y2 (hands down)
         db $16          ; Actor2 X4,Y1 (hands down)
         db $17          ; Actor2 X4,Y2 (hands down)
         db $1A          ; Actor2 X2,Y1 (hands up)
         db $1B          ; Actor2 X2,Y2 (hands up)
         db $1E          ; Actor2 X4,Y1 (hands up)
         db $1F          ; Actor2 X4,Y2 (hands up)

; Tile graphics pointers for odd-numbered shop actors
C36E27:  dw $03C0        ; 1,1 (hands down)
         dw $03E0        ; 1,2 (hands down)
         dw $0500        ; 2,1 (hands down)
         dw $0520        ; 2,2 (hands down)
         dw $0540        ; 3,1 (hands down)
         dw $0560        ; 3,2 (hands down)
         dw $FFFF        ; 4,1 (hands down)
         dw $FFFF        ; 4,2 (hands down)
         dw $03C0        ; 1,1 (hands up)
         dw $0660        ; 1,2 (hands up)
         dw $0680        ; 2,1 (hands up)
         dw $06A0        ; 2,2 (hands up)
         dw $06C0        ; 3,1 (hands up)
         dw $06E0        ; 3,2 (hands up)
         dw $FFFF        ; 4,1 (hands up)
         dw $FFFF        ; 4,2 (hands up)

; Tile graphics pointers for even-numbered shop actors
         dw $1A60        ; 1,1 (hands down)
         dw $1A80        ; 1,2 (hands down)
         dw $1BA0        ; 2,1 (hands down)
         dw $1BC0        ; 2,2 (hands down)
         dw $1BE0        ; 3,1 (hands down)
         dw $1C00        ; 3,2 (hands down)
         dw $FFFF        ; 4,1 (hands down)
         dw $FFFF        ; 4,2 (hands down)
         dw $1A60        ; 1,1 (hands up)
         dw $1D00        ; 1,2 (hands up)
         dw $1D20        ; 2,1 (hands up)
         dw $1D40        ; 2,2 (hands up)
         dw $1D60        ; 3,1 (hands up)
         dw $1D80        ; 3,2 (hands up)
         dw $FFFF        ; 4,1 (hands up)
         dw $FFFF        ; 4,2 (hands up)

; Upload cursor, arrow, and icon graphics (plus excess data)
C36E67:  REP #$20        ; 16-bit A
         LDY #$2000      ; $4000
         STY $2116       ; Set VRAM ptr
         LDX $00         ; Index: 0
C36E71:  LDA $ED5AC0,X   ; 8 px, 2 planes
         STA $2118       ; Save in VRAM
         INX             ; Index +1
         INX             ; Index +1
         CPX #$1400      ; At ED/6EC0?
         BNE C36E71      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Upload each member's portrait
C36E82:  LDX $00         ; 1st: Member 1
C36E84:  REP #$20        ; 16-bit A
         LDA.L C36F51,X  ; VRAM pointer
         STA $2116       ; Set destination
         LDY $6D,X       ; Actor's address
         PHX             ; Save mbr index
         TDC             ; Clear A
         SEP #$20        ; 8-bit A
         LDA $0014,Y     ; Status
         AND #$20        ; Imp?
         BEQ C36E9E      ; Branch if not
         LDA #$0F        ; Use Imp image
         BRA C36EA8      ; Ignore actor
C36E9E:  LDA $0000,Y     ; Actor
         CMP #$01        ; Locke?
         BEQ C36EA8      ; Branch if so
         LDA $0001,Y     ; Graphics set
C36EA8:  REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C36F1B,X  ; GFX pointer
         TAX             ; Index it
         JSR C37000      ; Upload portrait
         PLX             ; Member index
         INX             ; Member index +1
         INX             ; Member index +1
         CPX #$0008      ; Done 4 members?
         BNE C36E84      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Set to upload healed member's portrait
C36EBF:  LDA #$ED        ; Bank: ED
         STA $1F         ; Set src HB
         LDY #$0320      ; Bytes: 800
         STY $19         ; Set data size
         TDC             ; Clear A
         LDA $9C         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C36F51,X  ; VRAM pointer
         STA $1B         ; Set destination
         LDY $6D,X       ; Actor's address
         TDC             ; Clear A
         SEP #$20        ; 8-bit A
         LDA $0014,Y     ; Status
         AND #$20        ; Imp?
         BEQ C36EE5      ; Branch if not
         LDA #$0F        ; Use Imp image
         BRA C36EEF      ; Ignore actor
C36EE5:  LDA $0000,Y     ; Actor
         CMP #$01        ; Locke?
         BEQ C36EEF      ; Branch if so
         LDA $0001,Y     ; Graphics set
C36EEF:  REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C36F1B,X  ; GFX pointer
         CLC             ; ...
         ADC #$1D00      ; Add base adr
         STA $1D         ; Set src LBs
         SEP #$20        ; 8-bit A
         RTS

; Portrait palette assignments
C36F00:  db $00          ; 00: Terra
         db $01          ; 01: Locke
         db $02          ; 02: Cyan
         db $03          ; 03: Shadow
         db $04          ; 04: Edgar
         db $05          ; 05: Sabin
         db $06          ; 06: Celes
         db $07          ; 07: Strago
         db $08          ; 08: Relm
         db $09          ; 09: Setzer
         db $0A          ; 0A: Moogle
         db $0B          ; 0B: Gau
         db $0C          ; 0C: Gogo
         db $0D          ; 0D: Umaro
         db $0E          ; 0E: Soldier
         db $0F          ; 0F: Imp
         db $10          ; 10: Leo
         db $11          ; 11: Banon
         db $00          ; 12: Terra (unused; esper Terra)
         db $0E          ; 13: Soldier (unused; merchant)
         db $12          ; 14: Ghost
         db $00          ; 15: Terra (unused; Kefka)
         db $00          ; 16: Terra (unused; Gestahl)
         db $00          ; 17: Terra (unused; Gungho)
         db $00          ; 18: Terra (unused; Duane)
         db $00          ; 19: Terra (unused; dog)
         db $06          ; 1A: Celes (unused; Maria)

; Pointers to portrait graphics
C36F1B:  dw $0000        ; 00: Terra
         dw $0320        ; 01: Locke
         dw $0640        ; 02: Cyan
         dw $0960        ; 03: Shadow
         dw $0C80        ; 04: Edgar
         dw $0FA0        ; 05: Sabin
         dw $12C0        ; 06: Celes
         dw $15E0        ; 07: Strago
         dw $1900        ; 08: Relm
         dw $1C20        ; 09: Setzer
         dw $1F40        ; 0A: Mog
         dw $2260        ; 0B: Gau
         dw $2580        ; 0C: Gogo
         dw $28A0        ; 0D: Umaro
         dw $2BC0        ; 0E: Soldier
         dw $2EE0        ; 0F: Imp
         dw $3200        ; 10: Leo
         dw $3520        ; 11: Banon
         dw $0000        ; 12: Terra (unused; esper Terra)
         dw $2BC0        ; 13: Soldier (unused; merchant)
         dw $3840        ; 14: Ghost
         dw $0000        ; 15: Terra (unused; Kefka)
         dw $0000        ; 16: Terra (unused; Gestahl)
         dw $0000        ; 17: Terra (unused; Gungho)
         dw $0000        ; 18: Terra (unused; Duane)
         dw $0000        ; 19: Terra (unused; dog)
         dw $12C0        ; 1A: Celes (unused; Maria)

; VRAM pointers for portrait graphics
C36F51:  dw $2600        ; Member 1
         dw $2800        ; Member 2
         dw $2A00        ; Member 3
         dw $2C00        ; Member 4
         dw $2E00        ; Bogus...
         dw $3000        ; Bogus...
         dw $3200        ; Bogus...
         dw $3400        ; Bogus...

; List actor sprites for save file 1
C36F61:  LDY $91         ; Blank file?
         BEQ C36F80      ; Nobody if so
         LDX $00         ; Member slot: 1
C36F67:  LDA $69,X       ; Actor in slot
         BMI C36F73      ; Blank if none
         JSR C36F97      ; Get sprite set
         JSR C36FA6      ; Handle soldier
         BRA C36F75      ; Skip a line
C36F73:  LDA #$FF        ; Sprite: None
C36F75:  STA $7EAA71,X   ; Set sprite
         INX             ; Member slot +1
         CPX #$0004      ; Done all 4?
         BNE C36F67      ; Loop if not
         RTS

; Fork: Empty party
C36F80:  LDX $00         ; Sprites: 1-4
         BRA C36F84      ; ...
C36F84:  LDA #$FF        ; Sprite: None
         STA $7EAA71,X   ; Set sprite A
         STA $7EAA72,X   ; Set sprite B
         STA $7EAA73,X   ; Set sprite C
         STA $7EAA74,X   ; Set sprite D
         RTS

; Get actor's graphics set
C36F97:  PHX             ; Save X
         REP #$20        ; 16-bit A
         TXA             ; Actor number
         ASL A           ; Double it
         TAX             ; Index it
         LDY $6D,X       ; Actor's address
         SEP #$20        ; 8-bit A
         PLX             ; Restore X
         LDA $0001,Y     ; Graphics set
         RTS

; Choose between green or brown soldier
C36FA6:  CMP #$0E        ; Soldier sprite?
         BNE C36FB7      ; Exit if not
         LDA $1EA0       ; Event flags
         BIT #$08        ; Soldier disguise?
         BEQ C36FB5      ; Pick brown if not
         LDA #$16        ; Use green soldier
         BRA C36FB7      ; Exit
C36FB5:  LDA #$0E        ; Use brown soldier
C36FB7:  RTS

; List actor sprites for save file 2
C36FB8:  LDY $93         ; Blank file?
         BEQ C36FD7      ; Nobody if so
         LDX $00         ; Member slot: 1
C36FBE:  LDA $69,X       ; Actor in slot
         BMI C36FCA      ; Blank if none
         JSR C36F97      ; Get sprite set
         JSR C36FA6      ; Handle soldier
         BRA C36FCC      ; Skip a line
C36FCA:  LDA #$FF        ; Sprite: None
C36FCC:  STA $7EAA75,X   ; Set sprite
         INX             ; Member slot +1
         CPX #$0004      ; Done all 4?
         BNE C36FBE      ; Loop if not
         RTS

; Fork: Empty party
C36FD7:  LDX #$0004      ; Sprites: 5-8
         BRA C36F84      ; Blank sprites

; List actor sprites for save file 3
C36FDC:  LDY $95         ; Blank file?
         BEQ C36FFB      ; Nobody if so
         LDX $00         ; Member slot: 1
C36FE2:  LDA $69,X       ; Actor in slot
         BMI C36FEE      ; Blank if none
         JSR C36F97      ; Get sprite set
         JSR C36FA6      ; Handle soldier
         BRA C36FF0      ; Skip a line
C36FEE:  LDA #$FF        ; Sprite: None
C36FF0:  STA $7EAA79,X   ; Set sprite
         INX             ; Member slot +1
         CPX #$0004      ; Done all 4?
         BNE C36FE2      ; Loop if not
         RTS

; Fork: Empty party
C36FFB:  LDX #$0008      ; Sprites: 9-12
         BRA C36F84      ; Blank sprites

; Upload actor's portrait graphics
C37000:  LDY #$0190      ; Tiles: 25
C37003:  LDA $ED1D00,X   ; 8 px, 2 planes
         STA $2118       ; Save in VRAM
         INX             ; Index +1
         INX             ; Index +1
         DEY             ; One less word
         BNE C37003      ; Loop till last
         RTS

; Create a blank portrait for Lineup menu
C37010:  LDX #$9F51      ; 7E/9F51
         STX $2181       ; Set WRAM LBs
         LDX #$0190      ; Tiles: 25
C37019:  STZ $2180       ; 8 px, 1 plane
         STZ $2180       ; 8 px, 1 plane
         DEX             ; One less word
         BNE C37019      ; Loop till last
         RTS

; Validate SRAM markers
C37023:  REP #$20        ; 16-bit A
         LDA #$E41B      ; Square's marker
         CMP $307FF8     ; In file A?
         BEQ C37047      ; Okay if so
         CMP $307FFA     ; In file B?
         BEQ C37047      ; Okay if so
         CMP $307FFC     ; In file C?
         BEQ C37047      ; Okay if so
         CMP $307FFE     ; In file D?...
         BEQ C37047      ; Okay if so
         SEP #$20        ; 8-bit A
         JSR C3704B      ; Delete all SRAM
         CLC             ; Skip Load menu
         RTS             ; Exit
C37047:  SEP #$20        ; 8-bit A
         SEC             ; Call Load menu
         RTS

; Delete all saved data
C3704B:  PHB             ; Save DB
         LDA #$30        ; Bank: 30
         PHA             ; Put on stack
         PLB             ; Set DB to 30
         LDX #$0000      ; SRAM index: 0
         REP #$20        ; 16-bit A
C37055:  STZ $6000,X     ; Clear SRAM word
         INX             ; Index +1
         INX             ; Index +1
         STZ $6000,X     ; Clear SRAM word
         INX             ; Index +1
         INX             ; Index +1
         CPX #$2000      ; Fully cleared?
         BNE C37055      ; Loop if not
         SEP #$20        ; 8-bit A
         PLB             ; Restore DB
         RTS

; Reset saved cursor positions for main menu
C37068:  LDX #$0000      ; Index: 0
C3706B:  STZ $022B,X     ; Clear position
         INX             ; Point to next
         CPX #$001F      ; Past $0249?
         BNE C3706B      ; Loop if not
         LDA #$01        ; Skills: "Magic"
         STA $0237       ; Set for ally 1
         STA $0239       ; Set for ally 2
         STA $023B       ; Set for ally 3
         STA $023D       ; Set for ally 4
         RTS

; Mark all save files as Square's property
C37083:  REP #$20        ; 16-bit A
         LDA #$E41B      ; Square marker
         STA $307FF8     ; Mark file A
         STA $307FFA     ; Mark file B
         STA $307FFC     ; Mark file C
         STA $307FFE     ; No file D...
         SEP #$20        ; 8-bit A
         RTS

; Reset game data for Load menu
C3709B:  JSR C37068      ; Clear cursor mem
         LDY #$7FFF      ; Color: White
         STY $1D55       ; Set user font's
         LDA #$12        ; Buttons: A & B
         STA $1D50       ; Define purpose
         LDA #$34        ; Buttons: X & Y
         STA $1D51       ; Define purpose
         LDA #$56        ; Buttons: L & R
         STA $1D52       ; Define purpose
         LDA #$06        ; Button: Select
         STA $1D53       ; Define purpose
         LDA #$2A        ; Bat.Mode, etc.
         STA $1D4D       ; Define options
         TDC             ; Clear A
         TAY             ; Clear Y
         STY $1DC7       ; Save count: 0
         STZ $1D54       ; Mag.Order, etc.
         STZ $1D4E       ; Wallpaper, etc.
         STZ $1D4F       ; Pad assignments
         STY $1863       ; SRAM hours, mins
         STZ $1865       ; SRAM seconds
         STY $1860       ; Gold LBs
         STZ $1862       ; Gold HB
         STY $1866       ; Steps LBs
         STZ $1868       ; Steps HB
         STY $021B       ; Real hours, mins
         STY $021D       ; Real secs, frames
         JSR C36BBC      ; Reset skin colors
         RTS

; 2C: Initialize Lineup menu
C370E7:  JSR C370FC      ; Init variables
         STZ $4A         ; Cursor area: Top
         STZ $5A         ; Always 0...
         STZ $99         ; Always 0...
         JSR C3762A      ; List/Create actors
         JSR C37482      ; Load navig data
         JSR C3748B      ; Relocate cursor
         JMP C37114      ; Draw menu, etc.

; Initialize variables for Lineup menu
C370FC:  JSR C3352F      ; Reset/Stop stuff
         JSR C36904      ; Reset BGs' X/Y
         LDA #$03        ; 64x64 at $0000
         STA $2107       ; Set BG1 map loc
         LDA #$C0        ; Channels: 6, 7
         TRB $43         ; Halt HDMA 6+7...
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         LDA #$06        ; Status icons: Temp
         TSB $47         ; Set menu flag
         RTS

; Draw Lineup menu, etc.
C37114:  JSR C307B0      ; Queue cursor OAM
         JSR C375C5      ; Set to shift text
         JSR C37522      ; Draw boxes/title
         JSR C3793F      ; Create portrait
         JSR C37953      ; Draw actor info
         JSR C30EFD      ; Queue text upload
         LDA #$2D        ; C3/7168
         STA $27         ; Queue: Choice 1
         LDA #$66        ; C3/79FF
         STA $26         ; Next: Fade-in
         JMP C33541      ; BRT:1 + NMI

; 7D: Return to Lineup menu from Status menu
C37131:  JSR C370FC      ; Init variables
         LDA $5D         ; Backup of $99
         STA $99         ; Always 0...
         JSR C37677      ; Create/lock chars
         LDA $90         ; Go to party area?
         BNE C3714B      ; Branch if so
         JSR C37482      ; Load navig data
         LDY $8E         ; Old cursor loc
         STY $4D         ; Set as current
         JSR C3748B      ; Relocate cursor
         BRA C37165      ; Draw menu, etc.

; Fork: Back to party area
C3714B:  LDA $90         ; ...
         STA $4A         ; Cursor area: Top
         LDA $8D         ; Backup of $5A
         STA $5A         ; Always 0...
         JSR C373DB      ; Relocate cursor
         LDY $8E         ; Old cursor loc
         STY $4D         ; Set as current
         LDA $79         ; Cursor wrap flags
         STA $59         ; Restore them
         LDY $7A         ; Row/Col count
         STY $53         ; Restore format
         JSR C37415      ; Handle D-Pad
C37165:  JMP C37114      ; Draw menu, etc.

; 2D: Handle Lineup menu choice 1
C37168:  JSR C371B9      ; Cover D-Pad/stats
         BCC C371B8      ; If crossed center
         LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C371A9      ; Branch if not
         LDA $4B         ; Cursor slot
         CLC             ; Prepare ADC
         ADC $4A         ; +16 if on party
         ADC $5A         ; Always 0...
         TAX             ; Index sum
         LDA $7EAC8D,X   ; Locked slot?
         BMI C371A2      ; Fail if so
         JSR C30EB2      ; Sound: Click
         LDA $4B         ; Cursor slot
         STA $28         ; Set pick 1's
         LDA $4A         ; Cursor area
         STA $49         ; Set pick 1's
         LDA $5A         ; Always 0...
         STA $5B         ; Ditto...
         LDA #$2E        ; C3/720C
         STA $26         ; Next: Choice 2
         JSR C32F21      ; Create blinker
         LDA $4A         ; In party area?
         BEQ C371A1      ; Exit if not
         LDA #$02        ; Anim mode: 2
         STA $7E3649,X   ; Set blinker's
C371A1:  RTS

; Fork: Forced member
C371A2:  JSR C30EC0      ; Play buzzer
         JSR C3305D      ; Pixelate screen
         RTS

; Fork: Exit attempt
C371A9:  LDA $09         ; No-autofire keys
         BIT #$10        ; Pushing Start?
         BNE C371B5      ; Branch if so
         LDA $09         ; ...
         BIT #$80        ; Pushing B?
         BEQ C371B8      ; Exit if not
C371B5:  JSR C37296      ; Validate groups
C371B8:  RTS

; Handle D-Pad and update actor info in Lineup menu
C371B9:  JSR C375B8      ; Update char info
         LDA $0B         ; Semi-auto keys
         BIT #$04        ; Pushing down?
         BEQ C371DE      ; Branch if not
         LDA $4E         ; Cursor row
         CMP #$01        ; 2nd or 4th?
         BNE C371DE      ; Branch if not
         LDA $4A         ; In party area?
         BNE C371DE      ; Branch if so

; Fork: Enter party area
C371CC:  LDA #$10        ; Cursor slot: +16
         STA $4A         ; Set area mod
         LDA $99         ; Always 0...
         ASL A           ; x2...
         ASL A           ; x4...
         STA $5A         ; Always 0...
         JSR C373DB      ; Relocate cursor
         JSR C30EA3      ; Sound: Cursor
         CLC             ; Mark area exit
         RTS

; Fork: Handle up
C371DE:  LDA $0B         ; Semi-auto keys
         BIT #$08        ; Pushing up?
         BEQ C37206      ; Branch if not
         LDA $4E         ; On row 1 or 3?
         BNE C37206      ; Branch if not
         LDA $4A         ; In party area?
         BEQ C37206      ; Branch if not

; Fork: Exit party area
C371EC:  LDA $4D         ; Cursor column
         STA $5E         ; Set as former
         STZ $4A         ; Cursor area: Top
         STZ $5A         ; Always 0...
         JSR C37482      ; Load navig data
         LDA #$01        ; Row: 2nd
         STA $4E         ; Set cursor row
         JSR C3744C      ; Adjust column
         JSR C3748B      ; Relocate cursor
         JSR C30EA3      ; Sound: Cursor
         CLC             ; Mark area exit
         RTS

; Fork: Staying within same area
C37206:  JSR C37415      ; Handle D-Pad
         SEC             ; Unmark area exit
         RTS             ; ...
C3720B:  RTS

; 2E: Handle Lineup menu choice 2
C3720C:  JSR C371B9      ; Cover D-Pad/stats
         BCC C3720B      ; If crossed center
         LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C3727D      ; Branch if not
         TDC             ; Clear A
         LDA $4B         ; Cursor slot B
         CLC             ; Prepare ADC
         ADC $4A         ; +16 if on party
         ADC $5A         ; Always 0...
         STA $E0         ; Memorize sum
         TAX             ; Index it
         LDA $7EAC8D,X   ; Locked slot?
         BMI C3728F      ; Fail if so
         TDC             ; Clear A
         LDA $28         ; Cursor slot A
         CLC             ; Prepare ADC
         ADC $49         ; +16 if on party
         ADC $5B         ; Always 0...
         CMP $E0         ; Slots are same?
         BNE C37265      ; Swap chars if not

; Fork: Double-clicked a slot
C37234:  LDA $E0         ; Chosen slot
         TAX             ; Index it
         LDA $7E9D89,X   ; Empty slot?
         BMI C37277      ; Fail if so
         JSR C30EB2      ; Sound: Click
         LDA $59         ; Cursor wrap flags
         STA $79         ; Make backup copy
         LDY $53         ; Rows/Cols count
         STY $7A         ; Make backup copy
         LDY $4D         ; Cursor position
         STY $8E         ; Set return loc
         LDA $4A         ; Area indicator
         STA $90         ; Set for return
         LDA $5A         ; Always 0...
         STA $8D         ; Make a backup
         LDA $99         ; Always 0...
         STA $5D         ; Make a backup
         LDA #$42        ; C3/631D
         STA $27         ; Queue Status menu
         LDA #$67        ; C3/79F0
         STA $26         ; Next: Fade-out
         LDA #$7D        ; C3/7131
         STA $4C         ; Set return cmd
         RTS

; Fork: Swap slot contents
C37265:  JSR C30EB2      ; Sound: Click
         LDA #$07        ; Actors: Delete
         TRB $47         ; Set menu flag
         JSR C372F8      ; Swap positions
         JSR C311B0      ; Delete actors
         JSR C37613      ; Create actors
         BRA C37286      ; Next: Choice 1

; Fork: Double-clicked empty slot
C37277:  JSR C30EC0      ; Play buzzer
         JSR C3305D      ; Pixelate screen

; Fork: Handle B
C3727D:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C3728E      ; Exit if not
         JSR C30EA9      ; Sound: Cursor
C37286:  LDA #$2D        ; C3/7168
         STA $26         ; Next: Choice 1
         LDA #$05        ; Blinker: Off
         TRB $46         ; Set menu flag
C3728E:  RTS

; Fork: Forced member
C3728F:  JSR C30EC0      ; Play buzzer
         JSR C3305D      ; Pixelate screen
         RTS

; Handle attempt to exit Lineup menu
C37296:  TDC             ; Clear A
         TAX             ; Slot index: 0
         LDA $0201       ; Group count
         AND #$7F        ; Clear flag
         ASL A           ; x2
         ASL A           ; x4 members
         STA $F3         ; Set index cap
         STZ $F4         ; Clear its HB
C372A3:  STZ $E0         ; Members: 0
         LDY #$0004      ; Slots left: 4
C372A8:  LDA $7E9D99,X   ; Empty slot?
         BMI C372B0      ; Branch if so
         INC $E0         ; +1 member
C372B0:  INX             ; Slot index +1
         DEY             ; One less slot
         BNE C372A8      ; Loop till 4th
         LDA $E0         ; Empty party?
         BEQ C372CB      ; Fail if so
         CPX $F3         ; Last party?
         BNE C372A3      ; Loop if not
         JSR C30EA9      ; Sound: Cursor
         STZ $0205       ; Never read...
         LDA #$FF        ; Null value
         STA $27         ; Queue menu exit
         LDA #$67        ; C3/79F0
         STA $26         ; Next: Fade-out
         RTS

; Fork: Draw "You need <#> group(s)."
C372CB:  JSR C30EC0      ; Play buzzer
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDA $0201       ; Event data
         AND #$07        ; Group count
         CMP #$01        ; One group?
         BEQ C372E9      ; Branch if so
         LDY #C37AB7     ; Text pointer
         JSR C302F9      ; Draw message
         LDX #$392F      ; Tilemap pointer
         JSR C375F7      ; Draw group count
         BRA C372EF      ; Skip 2 lines

; Fork: Draw "No one there!"
C372E9:  LDY #C37ACE     ; Text pointer
         JSR C302F9      ; Draw message
C372EF:  LDA #$20        ; Frames: 32
         STA $20         ; Set wait timer
         LDA #$69        ; C3/7A87
         STA $26         ; Next: Wait
         RTS

; Swap actor positions in Lineup menu
C372F8:  TDC             ; Clear A
         LDA $28         ; Chosen slot A
         CLC             ; Prepare ADC
         ADC $49         ; +16 if on party
         ADC $5B         ; Always 0...
         TAX             ; Index sum
         LDA $7E9D89,X   ; Actor in slot A
         STA $E5         ; Memorize it
         BPL C37317      ; Branch if any

; Fork: Fake party info for empty slot A
C37309:  LDA $7E9E51,X   ; Party number
         ORA.L C373AF,X  ; Add roster slot
         STA $E0         ; Memorize it
         STZ $E1         ; Clear row...
         BRA C37326      ; Handle slot B

; Fork: Get party info of actor A
C37317:  TAY             ; Index actor A
         LDA $1850,Y     ; Party info
         AND #$DF        ; Discard row
         STA $E0         ; Memorize it
         LDA $1850,Y     ; Party info
         AND #$20        ; Isolate row
         STA $E1         ; Memorize it

; Fork: Get actor in slot B
C37326:  LDA $4B         ; Chosen slot B
         CLC             ; ...
         ADC $4A         ; +16 if on party
         ADC $5A         ; Always 0...
         TAX             ; Index sum
         LDA $7E9D89,X   ; Actor in slot B
         STA $E6         ; Memorize it
         BPL C37344      ; Branch if any

; Fork: Fake party info for empty slot B
C37336:  LDA $7E9E51,X   ; Party number
         ORA.L C373AF,X  ; Add roster slot
         STA $E2         ; Memorize it
         STZ $E3         ; Clear row...
         BRA C37353      ; Swap positions

; Fork: Get party info of actor B
C37344:  TAY             ; Index actor B
         LDA $1850,Y     ; Party info
         AND #$DF        ; Discard row
         STA $E2         ; Memorize it
         LDA $1850,Y     ; Party info
         AND #$20        ; Isolate row
         STA $E3         ; Memorize it

; Fork: Swap slot positions
C37353:  LDA $E0         ; Actor A info
         AND #$40        ; Object is on?
         BNE C37361      ; Branch if so
C37359:  LDA $E2         ; Actor B info
         AND #$40        ; Object is on?
         BNE C3737A      ; Branch if so
         BRA C37391      ; Swap menu slots

; Fork: Update party info for actor A
C37361:  TDC             ; ...
         LDA $28         ; Chosen slot A
         CLC             ; Prepare ADC
         ADC $49         ; +16 if on party
         ADC $5B         ; Always 0...
         TAX             ; Index sum
         LDA $7E9D89,X   ; Actor in slot A
         BMI C37359      ; Branch if none
         TAX             ; Index it
         LDA $E2         ; Actor B info
         ORA $E1         ; Add A's row
         STA $1850,X     ; Set A's info
         BRA C37359      ; Repeat for B

; Fork: Update party info for actor B
C3737A:  TDC             ; ...
         LDA $4B         ; Chosen slot B
         CLC             ; Prepare ADC
         ADC $4A         ; +16 if on party
         ADC $5A         ; Always 0...
         TAX             ; Index sum
         LDA $7E9D89,X   ; Actor in slot B
         BMI C37391      ; Branch if none
         TAX             ; Index it
         LDA $E0         ; Actor A info
         ORA $E3         ; Add B's row
         STA $1850,X     ; Set B's info

; Fork: Swap slot contents
C37391:  TDC             ; ...
         LDA $4B         ; Chosen slot B
         CLC             ; Prepare ADC
         ADC $4A         ; +16 if in party
         ADC $5A         ; Always 0...
         TAX             ; Index sum
         LDA $E5         ; Actor in slot A
         STA $7E9D89,X   ; Put in slot B
         LDA $28         ; Chosen slot A
         CLC             ; Prepare ADC
         ADC $49         ; +16 if in party
         ADC $5B         ; Always 0...
         TAX             ; Index sum
         LDA $E6         ; Actor in slot B
         STA $7E9D89,X   ; Put in slot A
         RTS

; Roster position and object status for Lineup menu slots
C373AF:  db $40          ; Non-party slot 1
         db $40          ; Non-party slot 2
         db $40          ; Non-party slot 3
         db $40          ; Non-party slot 4
         db $40          ; Non-party slot 5
         db $40          ; Non-party slot 6
         db $40          ; Non-party slot 7
         db $40          ; Non-party slot 8
         db $40          ; Non-party slot 9
         db $40          ; Non-party slot 10
         db $40          ; Non-party slot 11
         db $40          ; Non-party slot 12
         db $40          ; Non-party slot 13
         db $40          ; Non-party slot 14
         db $40          ; Non-party slot 15
         db $40          ; Non-party slot 16
         db $40          ; Party 1, NW
         db $48          ; Party 1, SW
         db $50          ; Party 1, NE
         db $58          ; Party 1, SE
         db $40          ; Party 2, NW
         db $48          ; Party 2, SW
         db $50          ; Party 2, NE
         db $58          ; Party 2, SE
         db $40          ; Party 3, NW
         db $48          ; Party 3, SW
         db $50          ; Party 3, NE
         db $58          ; Party 3, SE
         db $40          ; Party 4, NW (unused)
         db $48          ; Party 4, SW (unused)
         db $50          ; Party 4, NE (unused)
         db $58          ; Party 4, SE (unused)
         db $40          ; Party 5, NW (unused)
         db $48          ; Party 5, SW (unused)
         db $50          ; Party 5, NE (unused)
         db $58          ; Party 5, SE (unused)
         db $40          ; Party 6, NW (unused)
         db $48          ; Party 6, SW (unused)
         db $50          ; Party 6, NE (unused)
         db $58          ; Party 6, SE (unused)
         db $40          ; Party 7, NW (unused)
         db $48          ; Party 7, SW (unused)
         db $50          ; Party 7, NE (unused)
         db $58          ; Party 7, SE (unused)

; Load nav data for party area of Lineup menu, relocate cursor
C373DB:  LDA $4D         ; Cursor column
         STA $5E         ; Set as former
         LDA $0201       ; Group count
         AND #$7F        ; Clear flag
         CMP #$01        ; One group?
         BEQ C373F5      ; Branch if so
         CMP #$02        ; Two groups?
         BEQ C37405      ; Branch if so

; Fork: Three groups
C373EC:  JSR C374AF      ; Load navig data
         JSR C37432      ; Set cursor column
         JMP C374B8      ; Relocate cursor

; Fork: One group
C373F5:  JSR C37491      ; Load navig data
         LDA $5E         ; Old cursor column
         CMP #$01        ; First column?
         BCC C37400      ; Retain it if so
         LDA #$01        ; Column: 2nd
C37400:  STA $4D         ; Set new column
         JMP C3749A      ; Relocate cursor

; Fork: Two groups
C37405:  JSR C374A0      ; Load navig data
         LDA $5E         ; Old cursor column
         CMP #$03        ; Within first 3?
         BCC C37410      ; Retain it if so
         LDA #$03        ; Column: 4th
C37410:  STA $4D         ; Set new column
         JMP C374A9      ; Relocate cursor

; Handle D-Pad for Lineup menu
C37415:  LDA $4A         ; In party area?
         BEQ C3742F      ; Branch if not
         LDA $0201       ; Group count
         AND #$7F        ; Clear flag
         CMP #$01        ; One group?
         BEQ C3742C      ; Branch if so
         CMP #$02        ; Two groups?
         BEQ C37429      ; Branch if so
         JMP C374B5      ; Handle D-Pad

; Fork: Area with two groups
C37429:  JMP C374A6      ; Handle D-Pad

; Fork: Area with one group
C3742C:  JMP C37497      ; Handle D-Pad

; Fork: Non-party area
C3742F:  JMP C37488      ; Handle D-Pad

; Adjust cursor column upon entering 3-party area of Lineup menu
C37432:  LDA $5E         ; Former column
         LDX $00         ; Column index: 0
C37436:  CMP.L C37466,X  ; On this column?
         BEQ C37444      ; Relocate if so
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0010      ; Done 8 columns?
         BNE C37436      ; Loop if not
         RTS             ; Exit
C37444:  INX             ; Index +1
         LDA.L C37466,X  ; Intended column
         STA $4D         ; Set new column
         RTS

; Adjust cursor column upon leaving 3-party area of Lineup menu
C3744C:  LDA $5E         ; Former column
         LDX $00         ; Column index: 0
C37450:  CMP.L C37476,X  ; On this column?
         BEQ C3745E      ; Relocate if so
         INX             ; Index +1
         INX             ; Index +1
         CPX #$000C      ; Done 6 columns?
         BNE C37450      ; Loop if not
         RTS             ; Exit
C3745E:  INX             ; Index +1
         LDA.L C37476,X  ; Intended column
         STA $4D         ; Set new column
         RTS

; New cursor column upon entering 3-party area of Lineup menu
C37466:  db $00,$00      ; 1 -> 1
         db $01,$01      ; 2 -> 2
         db $02,$01      ; 3 -> 2
         db $03,$02      ; 4 -> 3
         db $04,$03      ; 5 -> 4
         db $05,$04      ; 6 -> 5
         db $06,$04      ; 7 -> 5
         db $07,$05      ; 8 -> 6

; New cursor column upon leaving 3-party area of Lineup menu
C37476:  db $00,$00      ; 1 -> 1
         db $01,$01      ; 2 -> 2
         db $02,$03      ; 3 -> 4
         db $03,$04      ; 4 -> 5
         db $04,$06      ; 5 -> 7
         db $05,$07      ; 6 -> 8

; Load navigation data for non-party area of Lineup menu
C37482:  LDY #C374BE     ; C3/74BE
         JMP C305FE      ; Load navig data

; Handle D-Pad for non-party area of Lineup menu
C37488:  JSR C3072D      ; Handle D-Pad
C3748B:  LDY #C374C3     ; C3/74C3
         JMP C30640      ; Relocate cursor

; Load navigation data for single-party area of Lineup menu
C37491:  LDY #C374E3     ; C3/74E3
         JMP C305FE      ; Load navig data

; Handle D-Pad for single-party area of Lineup menu
C37497:  JSR C3072D      ; Handle D-Pad
C3749A:  LDY #C374E8     ; C3/74E8
         JMP C30637      ; Relocate cursor

; Load navigation data for two-party area of Lineup menu
C374A0:  LDY #C374F0     ; C3/74F0
         JMP C305FE      ; Load navig data

; Handle D-Pad for two-party area of Lineup menu
C374A6:  JSR C3072D      ; Handle D-Pad
C374A9:  LDY #C374F5     ; C3/74F5
         JMP C30637      ; Relocate cursor

; Load navigation data for three-party area of Lineup menu
C374AF:  LDY #C37505     ; C3/7505
         JMP C305FE      ; Load navig data

; Handle D-Pad for three-party area of Lineup menu
C374B5:  JSR C3072D      ; Handle D-Pad
C374B8:  LDY #C3750A     ; C3/750A
         JMP C30637      ; Relocate cursor

; Navigation data for non-party area of Lineup menu
C374BE:  db $81          ; Never wraps
         db $00          ; Initial column
         db $00          ; Initial row
         db $08          ; 8 columns
         db $02          ; 2 rows

; Cursor positions for non-party area of Lineup menu
C374C3:  dw $6408        ; Slot 1
         dw $6424        ; Slot 2
         dw $6440        ; Slot 3
         dw $645C        ; Slot 4
         dw $6478        ; Slot 5
         dw $6494        ; Slot 6
         dw $64B0        ; Slot 7
         dw $64CC        ; Slot 8
         dw $8008        ; Slot 9
         dw $8024        ; Slot 10
         dw $8040        ; Slot 11
         dw $805C        ; Slot 12
         dw $8078        ; Slot 13
         dw $8094        ; Slot 14
         dw $80B0        ; Slot 15
         dw $80CC        ; Slot 16

; Navigation data for single-party area of Lineup menu
C374E3:  db $81          ; Never wraps
         db $00          ; Initial column
         db $00          ; Initial row
         db $02          ; 2 columns
         db $02          ; 2 rows

; Cursor positions for single-party area of Lineup menu
C374E8:  dw $A408        ; NW
         dw $A428        ; NE
         dw $C008        ; SW
         dw $C028        ; SE

; Navigation data for two-party area of Lineup menu
C374F0:  db $81          ; Never wraps
         db $00          ; Initial column
         db $00          ; Initial row
         db $04          ; 4 columns
         db $02          ; 2 rows

; Cursor positions for two-party area of Lineup menu
C374F5:  dw $A408        ; Party 1, NW
         dw $A428        ; Party 1, NE
         dw $A458        ; Party 2, NW
         dw $A478        ; Party 2, NE
         dw $C008        ; Party 1, SW
         dw $C028        ; Party 1, SE
         dw $C058        ; Party 2, SW
         dw $C078        ; Party 2, SE

; Navigation data for three-party area of Lineup menu
C37505:  db $81          ; Never wraps
         db $00          ; Initial column
         db $00          ; Initial row
         db $06          ; 6 columns
         db $02          ; 2 rows

; Cursor positions for three-party area of Lineup menu
C3750A:  dw $A408        ; Party 1, NW
         dw $A428        ; Party 1, NE
         dw $A458        ; Party 2, NW
         dw $A478        ; Party 2, NE
         dw $A4A8        ; Party 3, NW
         dw $A4C8        ; Party 3, NE
         dw $C008        ; Party 1, SW
         dw $C028        ; Party 1, SE
         dw $C058        ; Party 2, SW
         dw $C078        ; Party 2, SE
         dw $C0A8        ; Party 3, SW
         dw $C0C8        ; Party 3, SE

; Draw Lineup menu windows and uppermost text
C37522:  LDY #C375A0     ; C3/75A0
         JSR C30341      ; Draw stats box
         LDY #C3759C     ; C3/759C
         JSR C30341      ; Draw bottom box
         LDY #C375A4     ; C3/75A4
         JSR C30341      ; Draw middle box
         LDY #C375A8     ; C3/75A8
         JSR C30341      ; Draw message box
         LDY #C37598     ; C3/7598
         JSR C30341      ; Draw title box
         JSR C37572      ; Draw party boxes
         JSR C30E52      ; Upload windows
         JSR C3755F      ; Clear BG3 map A
         JSR C30E6E      ; Upload BG3 A+B
         JSR C36A15      ; Clear BG1 map A
         LDA #$24        ; Palette 1
         STA $29         ; Color: Blue
         LDY #C37AAE     ; Text pointer
         JSR C302F9      ; Draw "Lineup"
         JSR C37562      ; Draw "Form..."
         JMP C30E28      ; Upload BG1 A+B

; Clear BG3 tilemap A
C3755F:  JMP C36A3C      ; Clear BG3 map A

; Draw "Form <#> group(s)."
C37562:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDY #C37A95     ; Text pointer
         JSR C302F9      ; Draw "Form..."
         LDX #$3927      ; Tilemap pointer
         JMP C375F7      ; Draw group count

; Draw party windows for Lineup menu
C37572:  TDC             ; Clear A
         LDA $0201       ; Group count
         AND #$7F        ; Clear flag
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C3757D,X)  ; Draw windows

; Jump table for the above
C3757D:  dw C30000       ; Bogus...
         dw C37591       ; 1 group
         dw C3758B       ; 2 groups
         dw C37585       ; 3 groups

; Draw 3 party windows for Lineup menu
C37585:  LDY #C375B4     ; C3/75B4
         JSR C30341      ; Draw party 3 box

; Draw 2 party windows for Lineup menu
C3758B:  LDY #C375B0     ; C3/75B0
         JSR C30341      ; Draw party 2 box

; Draw 1 party window for Lineup menu
C37591:  LDY #C375AC     ; C3/75AC
         JSR C30341      ; Draw party 1 box
         RTS

; Window layout for Lineup menu
C37598:  dw $588B,$0206  ; 08x04 at $588B (Title)
C3759C:  dw $5CCB,$071C  ; 30x09 at $5CCB (Parties)
C375A0:  dw $598B,$051C  ; 30x07 at $598B (Stats)
C375A4:  dw $5B0B,$061C  ; 30x08 at $5B0B (Candidates)
C375A8:  dw $589B,$0214  ; 22x04 at $589B (Messages)
C375AC:  dw $5D0B,$0608  ; 10x08 at $5D0B (Party 1)
C375B0:  dw $5D1F,$0608  ; 10x08 at $5D1F (Party 2)
C375B4:  dw $5D33,$0608  ; 10x08 at $5D33 (Party 3)

; Update displayed actor info in Lineup menu
C375B8:  LDA #$06        ; Status icons: Temp
         TSB $47         ; Set menu flag
         JSR C37C2F      ; Queue face upload
         JSR C37CAE      ; Load face colors
         JMP C37953      ; Draw actor info

; Set to condense text in Lineup menu
C375C5:  LDA #$02        ; 1Rx2B to PPU
         STA $4350       ; Set DMA mode
         LDA #$0E        ; $210E
         STA $4351       ; To BG1 V-Scroll
         LDY #C375E4     ; C3/75E4
         STY $4352       ; Set CH5 src LBs
         LDA #$C3        ; Bank: C3
         STA $4354       ; Set CH5 src HB
         LDA #$C3        ; ...
         STA $4357       ; Set indir HB
         LDA #$20        ; Channel: 5
         TSB $43         ; Queue HDMA-5
         RTS

; Text shifting table for the above
C375E4:  db $20,$02,$00  ; Title
         db $08,$00,$00  ; Nothing
         db $0B,$04,$00  ; Nothing
         db $0C,$08,$00  ; Level
         db $0C,$0C,$00  ; HP
         db $0C,$10,$00  ; MP
         db $00          ; End

; Draw number of required groups for Lineup menu
C375F7:  TDC             ; Clear A
         LDA $0201       ; Event data
         AND #$07        ; Group count
         CLC             ; Prepare ADC
         ADC.B #!num0    ; Turn into text
         STA $F9         ; Add to string
         STZ $FA         ; End string
         STX $F7         ; Set position
         LDY #$00F7      ; 00/00F7
         STY $E7         ; Set src LBs
         LDA #$00        ; Bank: 00
         STA $E9         ; Set src HB
         JSR C302FF      ; Draw value
         RTS

; List members and create actors after changes in Lineup menu
C37613:  LDA #$FF        ; Actor: None
         LDX $00         ; Member slot: 1
C37617:  STA $7E9D99,X   ; Clear slot
         INX             ; Point to next
         CPX #$0090      ; Done 7 parties?
         BNE C37617      ; Loop if not
         JSR C376EA      ; Compile members
         JSR C37853      ; Create members
         JMP C37683      ; And candidates

; List and create actors in Lineup menu, define locked slots
C3762A:  LDA #$FF        ; Actor: None
         LDX $00         ; Menu slot: 1
C3762E:  STA $7E9D89,X   ; Clear slot
         INX             ; Point to next
         CPX #$00A0      ; Done party 7?
         BNE C3762E      ; Loop if not
         LDX #$9D89      ; 7E/9D89
         STX $2181       ; Set WRAM LBs
         LDA $0201       ; Forced members?
         BMI C37665      ; Branch if not

; Fork: Compile candidates, etc.
C37643:  LDX $00         ; 1st: Terra
C37645:  LDA $1850,X     ; Party info
         AND #$40        ; Object's off?
         BEQ C37657      ; Skip if so
         LDA $1850,X     ; Party info
         AND #$07        ; In a party?
         BNE C37657      ; Skip if so
         TXA             ; Actor's slot
         STA $2180       ; Add to list
C37657:  INX             ; Actor slot +1
         CPX #$0010      ; Done all 16?
         BNE C37645      ; Loop if not
         LDA #$FF        ; Null value
         STA $2180       ; End list
         JMP C37677      ; Make/lock chars

; Fork: Clear assigned party for all actors
C37665:  LDX $00         ; 1st: Terra
C37667:  LDA $1850,X     ; Party info
         AND #$F8        ; Clear party
         STA $1850,X     ; Save changes
         INX             ; Actor slot +1
         CPX #$0010      ; Done all 16?
         BNE C37667      ; Loop if not
         BRA C37643      ; Create actors

; List members, create actors, and define locked slots in Lineup menu
C37677:  JSR C376EA      ; Compile members
         JSR C37853      ; Create members
         JSR C37683      ; And candidates
         JMP C3790C      ; Set locked slots

; Create all candidates in Lineup menu
C37683:  LDX $00         ; Menu slot: 1
C37685:  TDC             ; Clear A
         LDA $7E9D89,X   ; Actor in slot
         BMI C376BF      ; Skip if none
         PHX             ; Save slot
         PHA             ; Save actor
         LDA #$00        ; ...
         PHA             ; ...
         PLB             ; ...
         LDA #$02        ; Min slot: 16
         LDY #C37A5F     ; C3/7A5F
         JSR C31173      ; Queue OAM fn
         TXY             ; Queue index
         TDC             ; Clear A
         PLA             ; Actor
         STA $7E35C9,X   ; Save for arrow
         JSR C378EB      ; Set anim ptr
         PLX             ; Menu slot
         LDA.L C376CA,X  ; X position
         STA $33CA,Y     ; Set sprite's
         LDA.L C376DA,X  ; Y position
         STA $344A,Y     ; Set sprite's
         TDC             ; Clear A
         STA $33CB,Y     ; No use...
         STA $344B,Y     ; No use...
         LDA #$D8        ; Bank: D8
         STA $35CA,Y     ; Set ptr HB
C376BF:  INX             ; Menu slot +1
         CPX #$0010      ; Done top 16?
         BNE C37685      ; Loop if not
         LDA #$00        ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         RTS

; X positions for candidates in Lineup menu
C376CA:  db $18          ; Slot 1
         db $34          ; Slot 2
         db $50          ; Slot 3
         db $6C          ; Slot 4
         db $88          ; Slot 5
         db $A4          ; Slot 6
         db $C0          ; Slot 7
         db $DC          ; Slot 8
         db $18          ; Slot 9
         db $34          ; Slot 10
         db $50          ; Slot 11
         db $6C          ; Slot 12
         db $88          ; Slot 13
         db $A4          ; Slot 14
         db $C0          ; Slot 15
         db $DC          ; Slot 16

; Y positions for candidates in Lineup menu
C376DA:  db $5C          ; Slot 1
         db $5C          ; Slot 2
         db $5C          ; Slot 3
         db $5C          ; Slot 4
         db $5C          ; Slot 5
         db $5C          ; Slot 6
         db $5C          ; Slot 7
         db $5C          ; Slot 8
         db $78          ; Slot 9
         db $78          ; Slot 10
         db $78          ; Slot 11
         db $78          ; Slot 12
         db $78          ; Slot 13
         db $78          ; Slot 14
         db $78          ; Slot 15
         db $78          ; Slot 16

; List members by ID and choice, link each menu slot to a party
C376EA:  LDX #$9DB9      ; 7E/9DB9
         STX $E7         ; Set WRAM LBs
         LDA $0201       ; Event data
         AND #$07        ; Group count
         STA $E6         ; Set counter
         LDA #$01        ; Party: 1st
         STA $E0         ; Set current
C376FA:  LDX $E7         ; WRAM adr LBs
         STX $2181       ; Set register
         LDX $00         ; 1st: Terra
C37701:  LDA $1850,X     ; Party info
         AND #$40        ; Object's off?
         BEQ C37715      ; Skip if so
         LDA $1850,X     ; Party info
         AND #$07        ; Isolate party
         CMP $E0         ; Matches ours?
         BNE C37715      ; Skip if not
         TXA             ; Actor slot
         STA $2180       ; Add to list
C37715:  INX             ; Actor slot +1
         CPX #$0010      ; Done all 16?
         BNE C37701      ; Loop if not
         LDA #$FF        ; Null value
         STA $2180       ; End party list
         REP #$20        ; 16-bit A
         LDA $E7         ; WRAM adr LBs
         CLC             ; Prepare ADC
         ADC #$0010      ; To next party
         STA $E7         ; Save changes
         SEP #$20        ; 8-bit A
         INC $E0         ; Actual party +1
         DEC $E6         ; One less left
         BNE C376FA      ; Loop till last
         JSR C37738      ; Sort by choice
         JMP C37802      ; Mark all slots

; Sort members by player choice, merge into a unified list
C37738:  LDA $0201       ; Event data
         AND #$07        ; Group count
         STA $E6         ; Set counter
         LDX $00         ; 1st: Party 1
C37741:  LDA #$7E        ; Bank: 7E
         STA $E9         ; Set dest HB
         REP #$20        ; 16-bit A
         LDA.L C377E6,X  ; Party RAM adr
         STA $E7         ; Set dest LBs
         LDA.L C377E6+2,X; Source index
         PHX             ; Save dst index
         TAX             ; Index source
         SEP #$20        ; 8-bit A
         JSR C37B25      ; Sort party
         PLX             ; Dst index
         INX             ; Dst index +1
         INX             ; Dst index +1
         INX             ; Dst index +1
         INX             ; Dst index +1
         DEC $E6         ; One less group
         BNE C37741      ; Loop till last

; Fork: Merge sorted lists
C37761:  LDX #$9D99      ; 7E/9D99
         STX $2181       ; Set WRAM LBs
         LDA $0201       ; Group count
         AND #$7F        ; Clear flag
         CMP #$01        ; One group?
         BEQ C377D6      ; Branch if so
         CMP #$02        ; Two groups?
         BEQ C377C3      ; Branch if so

; Fork: Add groups 1-3
C37774:  JSR C377C3      ; Add groups 1+2
         LDX $00         ; Member slot: 1
C37779:  LDA $7E9DE1,X   ; Actor in slot
         STA $2180       ; Add to list
         INX             ; Member slot +1
         CPX #$0004      ; Done 4 slots?
         BNE C37779      ; Loop if not

; Fork: Add group 4 (useless...)
C37786:  LDX $00         ; Member slot: 1
C37788:  LDA $7E9DF1,X   ; Actor in slot
         STA $2180       ; Add to list
         INX             ; Member slot +1
         CPX #$0004      ; Done 4 slots?
         BNE C37788      ; Loop if not

; Fork: Add group 5 (useless...)
C37795:  LDX $00         ; Member slot: 1
C37797:  LDA $7E9E01,X   ; Actor in slot
         STA $2180       ; Add to list
         INX             ; Member slot +1
         CPX #$0004      ; Done 4 slots?
         BNE C37797      ; Loop if not

; Fork: Add group 6 (useless...)
C377A4:  LDX $00         ; Member slot: 1
C377A6:  LDA $7E9E11,X   ; Actor in slot
         STA $2180       ; Add to list
         INX             ; Member slot +1
         CPX #$0004      ; Done 4 slots?
         BNE C377A6      ; Loop if not

; Fork: Add group 7 (useless...)
C377B3:  LDX $00         ; Member slot: 1
C377B5:  LDA $7E9E21,X   ; Actor in slot
         STA $2180       ; Add to list
         INX             ; Member slot +1
         CPX #$0004      ; Done 4 slots?
         BNE C377B5      ; Loop if not
         RTS

; Fork: Add groups 1 and 2
C377C3:  JSR C377D6      ; Add group 1
         LDX $00         ; Member slot: 1
C377C8:  LDA $7E9DD1,X   ; Actor in slot
         STA $2180       ; Add to list
         INX             ; Member slot +1
         CPX #$0004      ; Done 4 slots?
         BNE C377C8      ; Loop if not
         RTS

; Fork: Add group 1
C377D6:  LDX $00         ; Member slot: 1
C377D8:  LDA $7E9DC1,X   ; Actor in slot
         STA $2180       ; Add to list
         INX             ; Member slot +1
         CPX #$0004      ; Done 4 slots?
         BNE C377D8      ; Loop if not
         RTS

; Source and destination for sorting a party (ID -> choice)
C377E6:  dw $9DC1,$0030  ; P1: $9DB9 -> $9DC1
         dw $9DD1,$0040  ; P2: $9DC9 -> $9DD1
         dw $9DE1,$0050  ; P3: $9DD9 -> $9DE1
         dw $9DF1,$0060  ; P4: $9DE9 -> $9DF1 (unused)
         dw $9E01,$0070  ; P5: $9DF9 -> $9E01 (unused)
         dw $9E11,$0080  ; P6: $9E09 -> $9E11 (unused)
         dw $9E21,$0090  ; P7: $9E19 -> $9E21 (unused)

; Assign a party number to each slot in Lineup menu
C37802:  LDX #$9E51      ; 7E/9E51
         STX $2181       ; Set WRAM LBs
         LDA #$10        ; Candidates: 16
C3780A:  STZ $2180       ; Slot: No party
         DEC A           ; One less slot
         BNE C3780A      ; Loop till last
         LDA $0201       ; Event data
         AND #$07        ; Group count
         CMP #$01        ; One group?
         BEQ C37839      ; Branch if so
         CMP #$02        ; Two groups?
         BEQ C3783E      ; Branch if so
         JSR C3783E      ; Do group 1+2
         LDA #$03        ; Group: 3
         JSR C37846      ; Mark 4 slots
         LDA #$04        ; Group: 4...
         JSR C37846      ; Mark 4 slots
         LDA #$05        ; Group: 5...
         JSR C37846      ; Mark 4 slots
         LDA #$06        ; Group: 6...
         JSR C37846      ; Mark 4 slots
         LDA #$07        ; Group: 7...
         JMP C37846      ; Mark 4 slots

; Fork: 1 group
C37839:  LDA #$01        ; Group: 1
         JMP C37846      ; Mark 4 slots

; Fork: 2 groups
C3783E:  JSR C37839      ; Do group 1
         LDA #$02        ; Group: 2
         JMP C37846      ; ...
C37846:  STA $2180       ; Mark slot A
         STA $2180       ; Mark slot B
         STA $2180       ; Mark slot C
         STA $2180       ; Mark slot D
         RTS

; Create all party members in Lineup menu
C37853:  LDA $0201       ; Event data
         AND #$07        ; Group count
         STA $E6         ; Set counter
         LDX #$9DC1      ; 7E/9DC1
         STX $F3         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $F5         ; Set src HB
C37863:  LDA $4212       ; PPU status
         AND #$40        ; H-Blank?
         BEQ C37863      ; Loop if not
         LDA $99         ; Always 0...
         STA $211B       ; Set matrix A LB
         STZ $211B       ; Clear HB
         LDA #$B0        ; 176
         STA $211C       ; Set matrix B
         STA $211C       ; ...
         LDX $2134       ; Product LB
         STX $E4         ; Set base X

; Fork: Handle current party
C3787F:  LDX $00         ; Member slot: 1
C37881:  TDC             ; Clear A
         TXY             ; Member slot
         LDA [$F3],Y     ; Actor in slot
         STA $F6         ; ...
         BMI C378C0      ; Skip if nobody
         PHX             ; Save slot
         PHA             ; Save actor
         LDA #$00        ; ...
         PHA             ; ...
         PLB             ; ...
         LDA #$02        ; Min slot: 16
         LDY #C37B42     ; C3/7B42
         JSR C31173      ; Queue OAM fn
         TXY             ; Queue index
         TDC             ; Clear A
         PLA             ; Actor in slot
         STA $7E35C9,X   ; Put in queue
         JSR C378EB      ; Set anim ptr
         PLX             ; Member slot
         TDC             ; Clear A
         LDA.L C378E3,X  ; Relative X
         REP #$21        ; 16-bit A; C-
         ADC $E4         ; Add base X
         STA $33CA,Y     ; Set ally's X
         SEP #$20        ; 8-bit A
         LDA.L C378E7,X  ; Y position
         STA $344A,Y     ; Set ally's
         TDC             ; Clear A
         STA $344B,Y     ; No use...
         LDA #$D8        ; Bank: D8
         STA $35CA,Y     ; Set ptr HB
C378C0:  INX             ; Member slot +1
         CPX #$0004      ; Done all 4?
         BNE C37881      ; Loop if not

; Fork: Handle next party
C378C6:  REP #$20        ; 16-bit A
         LDA $F3         ; Party list adr
         CLC             ; Prepare ADC
         ADC #$0010      ; To next party
         STA $F3         ; Save changes
         LDA $E4         ; Base X pos
         CLC             ; Prepare ADC
         ADC #$0050      ; Go 80 px right
         STA $E4         ; Save changes
         SEP #$20        ; 8-bit A
         DEC $E6         ; One less group
         BNE C3787F      ; Loop till last
         LDA #$00        ; Clear A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         RTS

; Relative X positions for party members in Lineup menu
C378E3:  db $18          ; NW
         db $18          ; SW
         db $38          ; NE
         db $38          ; SE

; Y positions for party members in Lineup menu
C378E7:  db $9C          ; NW
         db $B8          ; SW
         db $9C          ; NE
         db $B8          ; SE

; Load pointer to actor's animation table
C378EB:  ASL A           ; Actor x2
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C36969,X  ; Actor address
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $0001,X     ; Sprite set
C378FA:  ASL A           ; Double it
         TAX             ; Index it
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         REP #$20        ; 16-bit A
         LDA $D8E917,X   ; Anim table ptr
         STA $32C9,Y     ; Set sprite's
         SEP #$20        ; 8-bit A
         RTS

; Establish locked actor slots in Lineup menu
C3790C:  LDX #$AC8D      ; 7E/AC8D
         STX $2181       ; Set WRAM LBs
         TDC             ; Clear A
         TAX             ; Menu slot: 1
C37914:  PHX             ; Save menu slot
         TDC             ; Clear A
         LDA $7E9D89,X   ; Actor in slot
         BMI C37933      ; Unlock if none
         REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C37C0F,X  ; Actor slot bit
         STA $E7         ; Memorize it
         LDA $0202       ; Forced actors
         AND $E7         ; Slot holds one?
         SEP #$20        ; 8-bit A
         BEQ C37933      ; Unlock if not
         LDA #$FF        ; Slot: Locked
         BRA C37934      ; Skip a line
C37933:  TDC             ; Slot: Unlocked
C37934:  STA $2180       ; Set slot status
         PLX             ; Current slot
         INX             ; Point to next
         CPX #$002C      ; Done all slots?
         BNE C37914      ; Loop if not
         RTS

; Initialize and load portrait for Lineup menu
C3793F:  STZ $28         ; Portr slot: 1
         JSR C37AE5      ; Init object
         LDA #$2F        ; Y: 47
         STA $7E344A,X   ; Set object's
         JSR C314AC      ; Upload graphics
         JSR C37C2F      ; Queue updating
         JMP C37CAE      ; Load palette

; Draw actor info in Lineup menu
C37953:  JSR C379AC      ; Erase BG1 text
         TDC             ; ...
         LDA $4B         ; Cursor slot
         CLC             ; Prepare ADC
         ADC $4A         ; +16 if in party
         ADC $5A         ; Always 0...
         TAX             ; Index sum
         LDA $7E9D89,X   ; Actor in slot
         BMI C379AB      ; Exit if nobody
         STA $C9         ; Memorize it
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C36969,X  ; Actor's address
         STA $67         ; Memorize it
         SEP #$20        ; 8-bit A
         LDA #$24        ; Palette 1
         STA $29         ; Color: Blue
         LDX #C379C9     ; Text ptrs loc
         LDY #$0006      ; Strings: 3
         JSR C369BA      ; Draw "LV/HP/MP"
         LDY #$3A5B      ; Class/KO pos
         LDX #$3048      ; Icon position
         LDA #$01        ; Anim mode: 1
         STA $48         ; Set for icons
         JSR C33427      ; Display status
         LDY #$3ADB      ; Text position
         JSR C334CF      ; Draw actor name
         LDY #$3B5B      ; Text position
         JSR C334E6      ; Draw held esper
         LDY #C379DE     ; Text pointer
         JSR C302F9      ; Draw HP's "/"
         LDY #C379E2     ; Text pointer
         JSR C302F9      ; Draw MP's "/"
         LDX #C379E6     ; Coords tbl ptr
         JSR C30C6C      ; Draw LV, HP, MP
C379AB:  RTS

; Erase actor info on BG1 in Lineup menu
C379AC:  LDX #$01C0      ; 7E/3A09
         REP #$20        ; 16-bit A
         TDC             ; Clear A
         LDA $00         ; ...
         LDY #$0060      ; Tiles: 192
C379B7:  STA $7E3849,X   ; Clear tile
         INX             ; Index +1
         INX             ; Index +1
         STA $7E3849,X   ; Clear tile
         INX             ; Index +1
         INX             ; Index +1
         DEY             ; 2 less tiles
         BNE C379B7      ; Loop till 0
         SEP #$20        ; 8-bit A
         RTS

; Text pointers for Lineup menu
C379C9:  dw C379CF       ; LV
         dw C379D4       ; HP
         dw C379D9       ; MP

; Positioned text for Lineup menu
C379CF:  dw $3A6D : db "LV",$00
C379D4:  dw $3AED : db "HP",$00
C379D9:  dw $3B6D : db "MP",$00
C379DE:  dw $3AFB : db "/",$00
C379E2:  dw $3B7B : db "/",$00

; Tilemap pointers for stats in Lineup menu
C379E6:  dw $3A77        ; LV
         dw $3AF3        ; HP
         dw $3AFD        ; Max HP
         dw $3B73        ; MP
         dw $3B7D        ; Max MP

; 67: Queue fade-out for Lineup menu
C379F0:  JSR C3304F      ; Queue fade-out
         LDY #$0008      ; Frames: 8
         STY $20         ; Set fade timer
         LDA #$68        ; C3/7A0E
         STA $26         ; Next: Wait
         JMP C375B8      ; Update char info

; 66: Queue fade-in for Lineup menu
C379FF:  JSR C33056      ; Queue fade-in
         LDY #$0008      ; Frames: 8
         STY $20         ; Set fade timer
         LDA #$68        ; C3/7A0E
         STA $26         ; Next: Wait
         JMP C375B8      ; Update char info

; 68: Wait while Lineup menu fades in or out
C37A0E:  LDY $20         ; Timer expired?
         BNE C37A16      ; Branch if not
         LDA $27         ; Queued command
         STA $26         ; Execute it next
C37A16:  JMP C375B8      ; Update char info

; Update arrow for gear data menu
C37A19:  TAX             ; Index mode
         JMP (C37A1D,X)  ; Handle mode

; Jump table for the above
C37A1D:  dw C37A21       ; Initialize arrow
         dw C37A3E       ; Sustain arrow

; Mode 0: Initialize arrow
C37A21:  LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         LDA #$EC6F      ; Anim table ptr
         STA $32C9,X     ; Set sprite's
         LDA #$0008      ; X: 8
         STA $33CA,X     ; Set sprite's
         SEP #$20        ; 8-bit A
         LDA #$D8        ; Bank: D8
         STA $35CA,X     ; Set ptr HB
         INC $3649,X     ; Mode +1
         JSR C31206      ; Set pose timer

; Mode 1: Sustain arrow
C37A3E:  LDY $2D         ; Queue index
         LDA $99         ; Arrow status
         BEQ C37A4B      ; Hide if bogus
         BMI C37A5D      ; Delete if off
         TDC             ; Clear A
         LDA #$02        ; Sprite: Normal
         BRA C37A4C      ; Skip a line
C37A4B:  TDC             ; Sprite: Blank
C37A4C:  TAX             ; Index A
         REP #$20        ; 16-bit A
         LDA $D8EC6B,X   ; Anim table ptr
         STA $32C9,Y     ; Set sprite's
         SEP #$20        ; ...
         JSR C31221      ; Define OAM
         SEC             ; Set to requeue
         RTS             ; Exit
C37A5D:  CLC             ; Set to dequeue
         RTS

; Update Lineup or Colosseum candidate, or enemy Shadow
C37A5F:  TAX             ; Index mode
         JMP (C37A63,X)  ; Handle mode

; Jump table for the above
C37A63:  dw C37A67       ; Initialize sprite
         dw C37A78       ; Sustain sprite

; Mode 0: Initialize sprite
C37A67:  LDA #$01        ; Hide actors: N
         TSB $47         ; Set menu flag
         LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         LDA #$01        ; ...
         JSR C31206      ; Set pose timer
         JSR C37BAE      ; No arrow...

; Mode 1: Sustain sprite
C37A78:  LDA $47         ; Menu flags
         AND #$01        ; Remove actors?
         BEQ C37A85      ; Delete if so
         LDX $2D         ; Queue index
         JSR C31221      ; Define OAM
         SEC             ; Set to requeue
         RTS             ; Exit
C37A85:  CLC             ; Set to dequeue
         RTS

; 69: Erase warning in Lineup menu after delay
C37A87:  LDA $20         ; Delay expired?
         BNE C37A92      ; Branch if not
         LDA #$2D        ; C3/7168
         STA $26         ; Next: Choice 1
         JSR C37562      ; Draw "Form..."
C37A92:  JMP C375B8      ; Update char info

; Positioned text for Lineup menu
C37A95:  dw $391D : db "Form   group(s).      ",$00
C37AAE:  dw $390D : db "Lineup",$00
C37AB7:  dw $391D : db "You need   group(s)!",$00
C37ACE:  dw $391D : db "No one there!       ",$00

; Create portrait for Lineup menu
C37AE5:  LDA #$03        ; Min slot: 24
         LDY #C30B12     ; C3/0B12
         JSR C31173      ; Queue OAM fn
         TXA             ; Queue index
         STA $60         ; Set sprite's
         PHB             ; Save DB
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         REP #$20        ; 16-bit A
         LDA #$001A      ; X: 26
         STA $33CA,X     ; Set sprite's
         SEP #$20        ; 8-bit A
         TDC             ; ...
         LDA $28         ; Portrait slot
         JSR C37B0E      ; Load anim ptr
         TDC             ; Clear A
         STA $344B,X     ; No use...
         JSR C31206      ; Set pose timer
         PLB             ; Restore DB
         RTS

; Load animation table address for portrait
C37B0E:  PHX             ; Queue index
         PHX             ; Push again
         ASL A           ; Port slot x2
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C30AE9,X  ; Anim table ptr
         PLY             ; Queue index
         STA $32C9,Y     ; Set sprite's
         SEP #$20        ; 8-bit A
         LDA #$C3        ; Bank: C3
         STA $35CA,Y     ; Set ptr HB
         PLX             ; Queue index
         RTS

; Sort members by actual order rather than actor slot
C37B25:  TDC             ; Clear A
         LDA $7E9D89,X   ; Actor slot
         STA $E1         ; Memorize it
         BMI C37B41      ; Exit if none
         PHX             ; List slot
         TAX             ; Actor slot
         LDA $1850,X     ; Party info
         AND #$18        ; Roster slot
         LSR A           ; Put in b2-b3
         LSR A           ; Put in b1-b2
         LSR A           ; Now 0-3
         TAY             ; Index it
         LDA $E1         ; Actor slot
         STA [$E7],Y     ; To new list
         PLX             ; List slot
         INX             ; List slot +1
         BRA C37B25      ; Do next slot
C37B41:  RTS

; Update conditional actor-related sprite
C37B42:  TAX             ; Index mode
         JMP (C37B46,X)  ; Handle mode

; Jump table for the above
C37B46:  dw C37B52       ; Initialize sprite V1
         dw C37B66       ; Initialize sprite V2
         dw C37B72       ; Initialize sprite V3
         dw C37B7E       ; Sustain sprite V1
         dw C37B8D       ; Sustain sprite V2
         dw C37BA1       ; Sustain sprite V3

; Mode 0: Init Lineup member, non-Lineup status icon, or arrow under actor; create arrow under forced member
C37B52:  LDA #$01        ; Ax like OBJs: N
         TSB $47         ; Set menu flag
         LDX $2D         ; Queue index
         LDA #$03        ; Mode: 3
         STA $3649,X     ; Set sprite's
         JSR C31206      ; Set pose timer
         TDC             ; Lineup member: Y
         JSR C37BAE      ; Add Lineup arrow
         BRA C37B7E      ; Define OAM

; Mode 1: Init Colosseum challenger or Lineup status icon
C37B66:  LDX $2D         ; Queue index
         LDA #$04        ; Mode: 4
         STA $3649,X     ; Set sprite's
         JSR C31206      ; Set pose timer
         BRA C37B8D      ; Define OAM

; Mode 2: Init unknown sprite (unused)
C37B72:  LDX $2D         ; Queue index
         LDA #$05        ; Mode: 5
         STA $3649,X     ; Set sprite's
         JSR C31206      ; Set pose timer
         BRA C37BA1      ; Define OAM

; Mode 3: Sustain Lineup member, non-Lineup status icon, or arrow under actor
C37B7E:  LDA $47         ; Menu flags
         AND #$01        ; Ax like objects?
         BEQ C37B8B      ; Delete if so
         LDX $2D         ; Queue index
         JSR C31221      ; Define OAM
         SEC             ; Set to requeue
         RTS             ; Exit
C37B8B:  CLC             ; Set to dequeue
         RTS

; Mode 4: Sustain Colosseum challenger or Lineup status icon
C37B8D:  LDA $47         ; Menu flags
         AND #$02        ; Temp sprite?
         BEQ C37B9A      ; Branch if not
         LDX $2D         ; Queue index
         JSR C31221      ; Define OAM
         CLC             ; Set to dequeue
         RTS             ; Exit
C37B9A:  LDX $2D         ; Queue index
         JSR C31221      ; Define OAM
         SEC             ; Set to requeue
         RTS

; Mode 5: Sustain unknown sprite (unused)
C37BA1:  LDA $47         ; Menu flags
         AND #$04        ; Ax like objects?
         BEQ C37B9A      ; Branch if not
         LDX $2D         ; Queue index
         JSR C31221      ; Define OAM
         CLC             ; Set to dequeue
         RTS

; Create large arrow under actor if forced into party
C37BAE:  STA $E6         ; Save pose timer
         LDA $0200       ; Menu number
         CMP #$04        ; Lineup menu?
         BNE C37C0E      ; Exit if not
         LDX $2D         ; Queue index
         TDC             ; Clear A
         LDA $35C9,X     ; Actor in slot
         BMI C37C0E      ; Exit if arrow
         ASL A           ; Double it
         REP #$20        ; 16-bit A
         TAX             ; Index it
         LDA.L C37C0F,X  ; Actor slot bit
         STA $E7         ; Memorize it
         LDA $0202       ; Forced actors
         AND $E7         ; Includes ours?
         SEP #$20        ; 8-bit A
         BEQ C37C0E      ; Exit if not
         LDA #$00        ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         LDA $E6         ; Party member?
         BNE C37BDF      ; Branch if not
         LDY #C37B42     ; C3/7B42
         BRA C37BE2      ; Skip a line
C37BDF:  LDY #C37A5F     ; C3/7A5F
C37BE2:  LDA #$03        ; Min slot: 24
         JSR C31173      ; Queue OAM fn
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         LDA #$FF        ; Actor: None
         STA $35C9,X     ; For C3/7BBD
         LDY $374A,X     ; Actor's index
         REP #$20        ; 16-bit A
         LDA $33CA,Y     ; Actor's X
         STA $33CA,X     ; Set arrow's
         LDA $344A,Y     ; Actor's Y
         STA $344A,X     ; Set arrow's
         LDA #$EBA9      ; Anim table ptr
         STA $32C9,X     ; Set arrow's
         SEP #$20        ; 8-bit A
         LDA #$D8        ; Bank: D8
         STA $35CA,X     ; Set ptr HB
C37C0E:  RTS

; Bitfield for actor slots
C37C0F:  dw $0001        ; Terra
         dw $0002        ; Locke
         dw $0004        ; Cyan
         dw $0008        ; Shadow
         dw $0010        ; Edgar
         dw $0020        ; Sabin
         dw $0040        ; Celes
         dw $0080        ; Strago
         dw $0100        ; Relm
         dw $0200        ; Setzer
         dw $0400        ; Mog
         dw $0800        ; Gau
         dw $1000        ; Gogo
         dw $2000        ; Umaro
         dw $4000        ; Guest 1
         dw $8000        ; Guest 2

; Set to upload portrait for Lineup menu
C37C2F:  LDY #$2600      ; $4C00
         STY $1B         ; Set VRAM ptr
         LDY #$0320      ; Bytes: 800
         STY $19         ; Set data size
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         CLC             ; Prepare ADC
         ADC $4A         ; +16 if on party
         ADC $5A         ; Always 0...
         TAX             ; Index sum
         LDA $7E9D89,X   ; Actor in slot
         BMI C37CA4      ; Blank if none
         BRA C37C6E      ; Set source

; Set to upload portrait A for Lineup group 5-8 (unused)
C37C4A:  LDY #$2600      ; $4C00
         STY $1B         ; Set VRAM ptr
         BRA C37C5F      ; Set source

; Set to upload portrait B for Lineup group 5-8 (unused)
C37C51:  LDY #$2800      ; $5000
         STY $1B         ; Set VRAM ptr
         BRA C37C5F      ; Set source

; Set to delete portrait B for Lineup group 5-8 (unused)
C37C58:  LDY #$2800      ; $5000
         STY $1B         ; Set VRAM ptr
         BRA C37CA4      ; Set source

; Fork: Set source for portrait B (unused part)
C37C5F:  LDY #$0320      ; Bytes: 800
         STY $19         ; Set data size
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         TAX             ; Index it
         LDA $7E9DA9,X   ; Actor in slot
         BMI C37CA4      ; Blank if none
C37C6E:  ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C36969,X  ; Actor address
         TAY             ; Index it
         TDC             ; Clear A
         SEP #$20        ; 8-bit A
         LDA $0014,Y     ; Status
         AND #$20        ; Imp?
         BEQ C37C85      ; Branch if not
         LDA #$0F        ; Use Imp image
         BRA C37C8F      ; Ignore actor
C37C85:  LDA $0000,Y     ; Actor
         CMP #$01        ; Locke?
         BEQ C37C8F      ; Branch if so
         LDA $0001,Y     ; Graphics set
C37C8F:  REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C36F1B,X  ; GFX pointer
         CLC             ; ...
         ADC #$1D00      ; Add base adr
         STA $1D         ; Set src LBs
         SEP #$20        ; 8-bit A
         LDA #$ED        ; Bank: ED
         STA $1F         ; Set src HB
         RTS

; Fork: Point to blank portrait
C37CA4:  LDY #$9F51      ; 7E/9F51
         STY $1D         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $1F         ; Set src HB
         RTS

; Load portrait palette for Lineup menu
C37CAE:  LDY $00         ; Palette: 0
         PHY             ; Save dest
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         CLC             ; Prepare ADC
         ADC $4A         ; +16 if on party
         ADC $5A         ; Always 0...
         TAX             ; Index sum
         LDA $7E9D89,X   ; Actor in slot
         BPL C37CD6      ; Branch if any
         TDC             ; Use Terra
         BRA C37CD6      ; Load palette

; Load portrait A's palette for Lineup group 5-8 (unused)
C37CC3:  LDY $00         ; Palette: 0
         BRA C37CCA      ; Skip a line

; Load portrait B's palette for Lineup group 5-8 (unused part)
C37CC7:  LDY #$0020      ; Palette: 1
C37CCA:  PHY             ; Save dest
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         TAX             ; Index it
         LDA $7E9DA9,X   ; Actor in slot
         BPL C37CD6      ; Branch if any
         TDC             ; Use Terra
C37CD6:  ASL A           ; Actor x2
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C36969,X  ; Actor's address
         TAY             ; Index it
         TDC             ; Clear A
         SEP #$20        ; 8-bit A
         LDA #$10        ; Colors: 16
         STA $E3         ; Set counter
         LDA $0014,Y     ; Status
         AND #$20        ; Imp?
         BEQ C37CF1      ; Branch if not
         LDA #$0F        ; Use Imp data
         BRA C37CF4      ; Skip a line
C37CF1:  LDA $0001,Y     ; Graphics set
C37CF4:  TAX             ; Index it
         LDA.L C36F00,X  ; Palette number
         REP #$20        ; 16-bit A
         ASL A           ; x2
         ASL A           ; x4
         ASL A           ; x8
         ASL A           ; x16
         ASL A           ; x32
         TAX             ; Index it
         PLY             ; RAM index
C37D02:  REP #$20        ; 16-bit A
         PHX             ; Save ROM index
         LDA $ED5860,X   ; Portrait color
         TYX             ; RAM index
         STA $7E3149,X   ; To OBJ pal 0
         SEP #$20        ; 8-bit A
         PLX             ; ROM index
         INX             ; ROM index +1
         INX             ; ROM index +1
         INY             ; RAM index +1
         INY             ; RAM index +1
         DEC $E3         ; One less color
         BNE C37D02      ; Loop till last
         SEP #$20        ; 8-bit A
         RTS

; Load navigation data for Item, Colosseum, or Sell menu
C37D1C:  LDY #C37D2B     ; C3/7D2B
         JMP C305FE      ; Load navig data

; Handle D-Pad for Item, Colosseum, or Sell menu
C37D22:  JSR C381C7      ; Handle D-Pad
C37D25:  LDY #C37D30     ; C3/7D30
         JMP C30648      ; Relocate cursor

; Navigation data for Item, Colosseum, and Sell menus
C37D2B:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $0A          ; 10 rows

; Cursor positions for Item, Colosseum, and Sell menus
C37D30:  dw $5C08        ; Item 1
         dw $6808        ; Item 2
         dw $7408        ; Item 3
         dw $8008        ; Item 4
         dw $8C08        ; Item 5
         dw $9808        ; Item 6
         dw $A408        ; Item 7
         dw $B008        ; Item 8
         dw $BC08        ; Item 9
         dw $C808        ; Item 10

; Load navigation data for rare item menu
C37D44:  LDY #C37D53     ; C3/7D53
         JMP C305FE      ; Load navig data

; Handle D-Pad for rare item menu
C37D4A:  JSR C3072D      ; Handle D-Pad
C37D4D:  LDY #C37D58     ; C3/7D58
         JMP C30640      ; Relocate cursor

; Navigation data for rare item menu
C37D53:  db $00          ; Wraps on all sides
         db $00          ; Initial column
         db $00          ; Initial row
         db $02          ; 2 columns
         db $0A          ; 10 rows

; Cursor positions for rare item menu
C37D58:  dw $5C08        ; Item 1
         dw $5C78        ; Item 2
         dw $6808        ; Item 3
         dw $6878        ; Item 4
         dw $7408        ; Item 5
         dw $7478        ; Item 6
         dw $8008        ; Item 7
         dw $8078        ; Item 8
         dw $8C08        ; Item 9
         dw $8C78        ; Item 10
         dw $9808        ; Item 11
         dw $9878        ; Item 12
         dw $A408        ; Item 13
         dw $A478        ; Item 14
         dw $B008        ; Item 15
         dw $B078        ; Item 16
         dw $BC08        ; Item 17
         dw $BC78        ; Item 18
         dw $C808        ; Item 19
         dw $C878        ; Item 20

; Load navigation data for Item menu options
C37D80:  LDY #C37D98     ; C3/7D98
         JMP C305FE      ; Load navig data

; Relocate cursor for Item menu options
C37D86:  LDY #C37D9D     ; C3/7D9D
         JMP C30640      ; Relocate cursor

; Handle D-Pad for Item menu options
C37D8C:  JSR C3072D      ; Handle D-Pad
         JSR C37D86      ; Relocate cursor
         LDY $4D         ; Cursor position
         STY $0234       ; To cursor memory
         RTS

; Navigation data for Item menu options
C37D98:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $03          ; 3 columns
         db $01          ; 1 row

; Cursor positions for Item menu options
C37D9D:  dw $1640        ; USE
         dw $1668        ; ARRANGE
         dw $16B0        ; RARE

; Draw Item menu with inventory; upload element graphics
C37DA3:  LDA #$01        ; 64x32 at $0000
         STA $2107       ; Set BG1 map loc
         LDY #C37E23     ; C3/7E23
         JSR C30341      ; Draw stats box A
         LDY #C37E27     ; C3/7E27
         JSR C30341      ; Draw stats box B
         LDY #C37E17     ; C3/7E17
         JSR C30341      ; Draw option box
         LDY #C37E13     ; C3/7E13
         JSR C30341      ; Draw title box
         LDY #C37E1B     ; C3/7E1B
         JSR C30341      ; Draw desc box
         LDY #C37E1F     ; C3/7E1F
         JSR C30341      ; Draw main box
         JSR C30E52      ; Upload windows
         JSR C36A3C      ; Clear BG3 map A
         JSR C36A41      ; Clear BG3 map B
         JSR C36A46      ; Clear BG3 map C
         JSR C36A4B      ; Clear BG3 map D
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         LDY #C38D16     ; Text pointer
         JSR C302F9      ; Draw "Item"
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDX #C38D10     ; Text ptrs loc
         LDY #$0006      ; Strings: 3
         JSR C369BA      ; Draw options
         JSR C3A73D      ; Build desc map
         JSR C3A9A9      ; Upload elements
         JSR C36A19      ; Clear BG1 map B
         JSR C37E0D      ; Draw inventory
         JSR C382F1      ; Desc; item count
         JSR C30E28      ; Upload BG1 A+B
         JSR C30E36      ; Upload BG1 B+C
         JSR C30E6E      ; Upload BG3 A+B
         JMP C30E7C      ; Upload BG3 C+D

; Draw inventory after clearing tilemap (Item, Colosseum, Sell)
C37E0D:  JSR C36A15      ; Clear BG1 map A
         JMP C37F88      ; Draw inventory

; Window layout for Item menu and gear data menu
C37E13:  dw $588B,$0204  ; 06x04 at $588B (Title)
C37E17:  dw $5897,$0216  ; 24x04 at $5897 (Options)
C37E1B:  dw $598B,$031C  ; 30x05 at $598B (Description)
C37E1F:  dw $5ACB,$0F1C  ; 30x17 at $5ACB (Main)
C37E23:  dw $60AD,$180D  ; 15x26 at $60AD (Gear stats; L part)
C37E27:  dw $5885,$1801  ; 03x26 at $5885 (Gear stats; R part)

; Set to condense text in Item, Colosseum, or Sell menu
C37E2B:  LDA #$02        ; 1Rx2B to PPU
         STA $4350       ; Set CH5 mode
         LDA #$12        ; $2112
         STA $4351       ; To BG3 V-Scroll
         LDY #C37F57     ; C3/7F57
         STY $4352       ; Set CH5 src LBs
         LDA #$C3        ; Bank: C3
         STA $4354       ; Set CH5 src HB
         LDA #$C3        ; ...
         STA $4357       ; Set indir HB
         LDA #$20        ; Channel: 5
         TSB $43         ; Queue HDMA-5
         JSR C37E95      ; Load BG1 V-Data
         LDX $00         ; Index: 0
C37E4E:  LDA.L C37EDA,X  ; BG1 H-Pan data
         STA $7E9A09,X   ; Save in RAM
         INX             ; Index +1
         CPX #$000D      ; End of table?
         BNE C37E4E      ; Loop if not
         LDA #$02        ; 1Rx2B to PPU
         STA $4360       ; Set CH6 mode
         LDA #$0D        ; $210D
         STA $4361       ; To BG1 H-Scroll
         LDY #$9A09      ; 7E/9A09
         STY $4362       ; Set CH6 src LBs
         LDA #$7E        ; Bank: 7E
         STA $4364       ; Set CH6 src HB
         LDA #$7E        ; ...
         STA $4367       ; Set indir HB
         LDA #$02        ; 1Rx2B to PPU
         STA $4370       ; Set CH7 mode
         LDA #$0E        ; $210E
         STA $4371       ; To BG1 V-Scroll
         LDY #$9849      ; 7E/9849
         STY $4372       ; Set CH7 src LBs
         LDA #$7E        ; Bank: 7E
         STA $4374       ; Set CH7 src HB
         LDA #$7E        ; ...
         STA $4377       ; Set indir HB
         LDA #$C0        ; Channels: 6, 7
         TSB $43         ; Queue HDMA 6+7
         RTS

; Load BG1 vertical shift table for Item, Colosseum, or Sell menu
C37E95:  LDX $00         ; Index: 0
C37E97:  LDA.L C37EE7,X  ; Void's V-Data
         STA $7E9849,X   ; Save in RAM
         INX             ; Index +1
         CPX #$0012      ; At items?
         BNE C37E97      ; Loop if not
C37EA5:  LDA.L C37EE7,X  ; Scanline data
         STA $7E9849,X   ; Save in RAM
         INX             ; Index +1
         TDC             ; Clear A
         LDA $49         ; Top BG1 row
         ASL A           ; x2
         ASL A           ; x4
         ASL A           ; x8
         ASL A           ; x16
         AND #$FF        ; ...
         REP #$20        ; 16-bit A
         CLC             ; Prepare ADC
         ADC.L C37EE7,X  ; Add V-Pan data
         STA $7E9849,X   ; Save in RAM
         SEP #$20        ; 8-bit A
         INX             ; Index +1
         INX             ; Index +1
         CPX #$006C      ; Beyond items?
         BNE C37EA5      ; Loop if not
C37ECB:  LDA.L C37EE7,X  ; Void's V-Data
         STA $7E9849,X   ; Save in RAM
         INX             ; Index +1
         CPX #$0070      ; End of table?
         BNE C37ECB      ; Loop if not
         RTS

; BG1 H-Shift table for inventory-style menus
C37EDA:  db $28,$00,$01  ; Nothing
         db $2F,$00,$01  ; Nothing
         db $78,$00,$00  ; Items
         db $1E,$00,$01  ; Nothing
         db $00          ; End

; BG1 V-Shift table for inventory-style menus
C37EE7:  db $27,$80,$00  ; Nothing?
         db $08,$00,$00  ; Nothing?
         db $0C,$04,$00  ; Nothing?
         db $0C,$08,$00  ; Nothing?
         db $08,$80,$00  ; Nothing?
         db $08,$00,$00  ; Nothing?
         db $04,$AC,$FF  ; Item row 1
         db $04,$AC,$FF  ; Item row 2
         db $04,$AC,$FF  ; Item row 3
         db $04,$B0,$FF  ; Item row 4
         db $04,$B0,$FF  ; Item row 5
         db $04,$B0,$FF  ; Item row 6
         db $04,$B4,$FF  ; Item row 7
         db $04,$B4,$FF  ; Item row 8
         db $04,$B4,$FF  ; Item row 9
         db $04,$B8,$FF  ; Item row 10
         db $04,$B8,$FF  ; Item row 11
         db $04,$B8,$FF  ; Item row 12
         db $04,$BC,$FF  ; Item row 13
         db $04,$BC,$FF  ; Item row 14
         db $04,$BC,$FF  ; Item row 15
         db $04,$C0,$FF  ; Item row 16
         db $04,$C0,$FF  ; Item row 17
         db $04,$C0,$FF  ; Item row 18
         db $04,$C4,$FF  ; Item row 19
         db $04,$C4,$FF  ; Item row 20
         db $04,$C4,$FF  ; Item row 21
         db $04,$C8,$FF  ; Item row 22
         db $04,$C8,$FF  ; Item row 23
         db $04,$C8,$FF  ; Item row 24
         db $04,$CC,$FF  ; Item row 25
         db $04,$CC,$FF  ; Item row 26
         db $04,$CC,$FF  ; Item row 27
         db $04,$D0,$FF  ; Item row 28
         db $04,$D0,$FF  ; Item row 29
         db $04,$D0,$FF  ; Item row 30
         db $1E,$00,$00  ; Nothing
         db $00          ; End

; BG3 V-Shift table for Item and Colosseum menus
C37F57:  db $2F,$00,$00  ; Title
         db $0C,$04,$00  ; Desc row 1
         db $0C,$08,$00  ; Desc row 2
         db $0C,$0C,$00  ; 2-hand
         db $0C,$10,$00  ; 50% Dmg
         db $0C,$14,$00  ; Vigor
         db $0C,$18,$00  ; Speed
         db $0C,$1C,$00  ; Stamina
         db $0C,$20,$00  ; Mag.Pwr
         db $0C,$24,$00  ; Bat.Pwr
         db $0C,$28,$00  ; Defense
         db $0C,$2C,$00  ; Evade
         db $0C,$30,$00  ; Mag.Def
         db $0C,$34,$00  ; MBlock
         db $0C,$38,$00  ; Nothing
         db $0C,$3C,$00  ; Nothing
         db $00          ; End

; Draw inventory for Item, Colosseum, or Sell menu
C37F88:  JSR C383F7      ; Define $E5, $E6
         LDY #$000A      ; Rows left: 10
C37F8E:  PHY             ; Save counter
         JSR C37FA1      ; Draw item info
         INC $E5         ; Item slot +1
         LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         INC A           ; Go 1 row down
         AND #$1F        ; Stay in limits
         STA $E6         ; Save changes
         PLY             ; Rows left
         DEY             ; One less left
         BNE C37F8E      ; Loop till last
         RTS

; Draw item's name, quantity owned, and class
C37FA1:  TDC             ; Clear A
         LDA $E5         ; Item slot
         TAY             ; Index it
         JSR C38045      ; Choose palette
         LDA $1969,Y     ; Item quantity
         JSR C304E0      ; Turn into text
         LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         LDX #$0011      ; X: 17
         JSR C3809F      ; Compute map ptr
         JSR C304B6      ; Draw quantity
         LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         LDX #$0003      ; X: 3
         JSR C3809F      ; Compute map ptr
         REP #$20        ; 16-bit A
         TXA             ; ...
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $E5         ; Item slot
         TAY             ; Index it
         JSR C380B9      ; Load "<item>:"
         JSR C37FD9      ; Draw string
         JMP C37FE6      ; Draw item class

; Draw memorized string
C37FD9:  LDY #$9E89      ; 7E/9E89
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         JSR C302FF      ; Draw string
         RTS

; Draw item class for Item, Colosseum, or Sell menu
C37FE6:  REP #$20        ; 16-bit A
         LDA $7E9E89     ; Text position
         CLC             ; Prepare ADC
         ADC #$0024      ; Skip item name
         STA $7E9E89     ; Save changes
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $7E9E8B     ; Item icon
         CMP #$FF        ; None?
         BEQ C3802C      ; Blank if so
         SEC             ; Prepare SBC
         SBC #!icon      ; Now 0-15
         STA $E0         ; Memorize it
         ASL A           ; x2
         ASL A           ; x4
         STA $E2         ; Memorize it
         LDA $E0         ; 0-15 icon
         ASL A           ; x2
         CLC             ; ...
         ADC $E2         ; x6
         ADC $E0         ; x7
         TAX             ; Index it
         LDY #$9E8B      ; 7E/9E8B
         STY $2181       ; Set WRAM LBs
         LDY #$0007      ; Letters: 7
C3801A:  LDA $D26F00,X   ; Letter
         STA $2180       ; Add to string
         INX             ; Point to next
         DEY             ; One less left
         BNE C3801A      ; Loop till last
         TDC             ; Terminator
         STA $2180       ; End string
         JMP C37FD9      ; Draw string

; Fork: Blank item class
C3802C:  LDY #$9E8B      ; 7E/9E8B
         STY $2181       ; Set WRAM LBs
         LDY #$0007      ; Spaces: 7
         LDA #$FF        ; Space char
C38037:  STA $2180       ; Add to string
         INX             ; ...
         DEY             ; One less left
         BNE C38037      ; Loop till last
         TDC             ; Terminator
         STA $2180       ; End string
         JMP C37FD9      ; Draw 7 spaces

; Choose item's color for Item, Colosseum, or Sell menu
C38045:  LDA $0200       ; Root menu
         CMP #$03        ; Shop menu?
         BEQ C38085      ; Enable if so
         CMP #$07        ; Colosseum?
         BEQ C38085      ; Enable if so
         BRA C38056      ; Handle main menu

; Fork: Get item slot (unused)
C38052:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
         TAY             ; Index it

; Fork: Main menu
C38056:  LDA $1869,Y     ; Item in slot
         CMP #$EF        ; Megalixir?
         BEQ C3808A      ; Disable if so
         CMP #$FF        ; None?
         BEQ C38085      ; Enable if so
         CMP #$F7        ; Tent?
         BEQ C3808F      ; Branch if so
         CMP #$F6        ; Sleeping Bag?
         BEQ C3808F      ; Branch if so
         CMP #$FD        ; Warp Stone?
         BEQ C38096      ; Branch if so
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85000,X   ; Properties
         AND #$07        ; Get class
         CMP #$06        ; Consumable?
         BNE C3808A      ; Disable if not
         LDA $D85000,X   ; Properties
         AND #$40        ; Usable in field?
         BEQ C3808A      ; Disable if not
C38085:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         RTS

; Fork: Set color to gray
C3808A:  LDA #$28        ; Palette 2
         STA $29         ; Color: Gray
         RTS

; Fork: Tent or Sleeping Bag
C3808F:  LDA $0201       ; Can save here?
         BMI C38085      ; Enable if so
         BRA C3808A      ; Color: Gray

; Fork: Warp Stone
C38096:  LDA $0201       ; Area permissions
         BIT #$02        ; Can warp here?
         BNE C38085      ; Enable if so
         BRA C3808A      ; Color: Gray

; Compute position into BG1 tilemap A
C3809F:  XBA             ; Switch to HB
         LDA $00         ; Clear it
         XBA             ; Y position
         REP #$20        ; 16-bit A
         ASL A           ; x2
         ASL A           ; x4
         ASL A           ; x8
         ASL A           ; x16
         ASL A           ; x32
         ASL A           ; x64
         STA $E7         ; Memorize it
         TXA             ; X position
         ASL A           ; Double it
         CLC             ; Prepare ADC
         ADC $E7         ; Add Y x64
         ADC #$3849      ; Add base adr
         TAX             ; Put sum in X
         SEP #$20        ; 8-bit A
         RTS

; Load owned item's name, add colon (Item, Colosseum, Sell)
C380B9:  LDX #$9E8B      ; 7E/9E8B
         STX $2181       ; Set WRAM LBs
C380BF:  LDA $4212       ; PPU status
         AND #$40        ; H-Blank?
         BEQ C380BF      ; Loop if not
         TDC             ; Clear A
         LDA $1869,Y     ; Item in slot
         CMP #$FF        ; None?
         BEQ C380F6      ; Blank if so
C380CE:  STA $211B       ; Set matrix A LB
         STZ $211B       ; Clear HB
         LDA #$0D        ; Name data size
         STA $211C       ; Set matrix B
         STA $211C       ; ...
         LDX $2134       ; Index product
         LDY #$000D      ; Letters: 13
C380E2:  LDA $D2B300,X   ; Letter
         STA $2180       ; Add to string
         INX             ; Point to next
         DEY             ; One less left
         BNE C380E2      ; Loop till last
         LDA.B #!coln    ; Char: ":"
         STA $2180       ; Add to string
         STZ $2180       ; End string
         RTS

; Fork: Blank item name, colon, and quantity
C380F6:  LDY #$0010      ; Spaces: 16
         LDA #$FF        ; Space char
C380FB:  STA $2180       ; Add to string
         DEY             ; One less left
         BNE C380FB      ; Loop till last
         STZ $2180       ; End string
         RTS

; Adjust BG1 vertical shift amounts while list scrolls
C38105:  LDX #$0012      ; Scanline: 88th
C38108:  SEP #$20        ; 8-bit A
         LDA $7E9849,X   ; Scanline amount
         CMP #$1E        ; Last 30 lines?
         BEQ C3815E      ; Exit if so
         INX             ; RAM index +1
         PHX             ; Memorize it
         TDC             ; Clear A
         LDA $20         ; Scroll timer
         REP #$20        ; 16-bit A
         LDY $41         ; Scrolling up?
         BMI C3811F      ; Branch if so
         BRA C38123      ; Skip 2 lines
C3811F:  CLC             ; Prepare ADC
         ADC #$0003      ; Timer +3
C38123:  ASL A           ; Timer x2
         TAX             ; Index it
         TAY             ; Memorize it
         LDA.L C3815F,X  ; Shift mod; R1/3
         PLX             ; RAM index
         CLC             ; Prepare ADC
         ADC $7E9849,X   ; Add actual shift
         STA $7E9849,X   ; Set actual shift
         INX             ; RAM index +1
         INX             ; RAM index +1
         INX             ; RAM index +1
         PHX             ; Memorize it
         TYX             ; ROM index
         LDA.L C3816B,X  ; Shift mod; R2/3
         PLX             ; RAM index
         CLC             ; Prepare ADC
         ADC $7E9849,X   ; Add actual shift
         STA $7E9849,X   ; Set actual shift
         INX             ; RAM index +1
         INX             ; RAM index +1
         INX             ; RAM index +1
         PHX             ; Memorize it
         TYX             ; ROM index
         LDA.L C38177,X  ; Shift mod; R3/3
         PLX             ; RAM index
         CLC             ; Prepare ADC
         ADC $7E9849,X   ; Add actual shift
         STA $7E9849,X   ; Set actual shift
         INX             ; RAM index +1
         INX             ; RAM index +1
         BRA C38108      ; Do next 12 lines
C3815E:  RTS

; Shift amount for 1st of every 3 rows of list scrolling down
C3815F:  dw $0008        ; Frame 3: +8 px down
         dw $0004        ; Frame 2: +4 px down
         dw $0004        ; Frame 1: +4 px down

; Shift amount for 1st of every 3 rows of list scrolling up
         dw $FFFC        ; Frame 3: +4 px up
         dw $FFFC        ; Frame 2: +4 px up
         dw $FFF8        ; Frame 1: +8 px up

; Shift amount for 2nd of every 3 rows of list scrolling down
C3816B:  dw $0004        ; Frame 3: +4 px down
         dw $0008        ; Frame 2: +8 px down
         dw $0004        ; Frame 1: +4 px down

; Shift amount for 2nd of every 3 rows of list scrolling up
         dw $FFFC        ; Frame 3: +4 px up
         dw $FFF8        ; Frame 2: +8 px up
         dw $FFFC        ; Frame 1: +4 px up

; Shift amount for every 3rd row of list scrolling down
C38177:  dw $0004        ; Frame 3: +4 px down
         dw $0004        ; Frame 2: +4 px down
         dw $0008        ; Frame 1: +8 px down

; Shift amount for every 3rd row of list scrolling up
         dw $FFF8        ; Frame 3: +8 px up
         dw $FFFC        ; Frame 2: +4 px up
         dw $FFFC        ; Frame 1: +4 px up

; Update scroll parameters for list
C38183:  TAX             ; Index mode
         JMP (C38187,X)  ; Handle mode

; Jump table for the above
C38187:  dw C3818F       ; Scroll upward
         dw C3819C       ; Scroll downward
         dw C381A7       ; Set timer
         dw C381B0       ; Check timer

; Mode 0: Scroll upward
C3818F:  LDX $2D         ; ...
         REP #$20        ; 16-bit A
         LDA #$FFFC      ; 4 px up
         STA $41         ; Set V-Speed
         SEP #$20        ; 8-bit A
         BRA C381A7      ; Init timer

; Mode 1: Scroll downward
C3819C:  LDX $2D         ; ...
         REP #$20        ; 16-bit A
         LDA #$0004      ; 4 px down
         STA $41         ; Set V-Speed
         SEP #$20        ; 8-bit A

; Mode 2: Set timer
C381A7:  LDX $2D         ; Queue index
         LDA #$03        ; Mode: 3
         STA $3649,X     ; Set next mode
         STA $20         ; Set timer

; Mode 3: Check timer
C381B0:  LDX $2D         ; ...
         LDA $20         ; Timer expired?
         BEQ C381BC      ; Stop if so
         LDA #$20        ; Scroll BG1: Y
         TSB $46         ; Set menu flag
         SEC             ; Set to requeue
         RTS

; Fork: Stop scrolling
C381BC:  LDY $00         ; Clear Y
         STY $41         ; BG1 V-Speed: 0
         LDA #$20        ; Scroll BG1: N
         TRB $46         ; Set menu flag
         CLC             ; Set to dequeue
         RTS             ; ...
C381C6:  RTS

; Handle D-Pad for scrollable list, change row when wrapping
C381C7:  LDA $20         ; Scrolling now?
         BNE C381C6      ; Exit if so

; Fork: Handle up
C381CB:  LDA $0B         ; Semi-auto keys
         BIT #$08        ; Pushing up?
         BEQ C381EA      ; Branch if not
         LDA $4E         ; On first row?
         BNE C381E2      ; Go up if not
         LDA $4A         ; At top of list?
         BEQ C381C6      ; Exit if so
         DEC $50         ; List row -1
         JSR C38286      ; Queue scrolling
         JSR C30EA3      ; Sound: Cursor
         RTS

; Fork: Move cursor up
C381E2:  DEC $50         ; List row -1
         DEC $4E         ; Cursor row -1
         JSR C30EA3      ; Sound: Cursor
         RTS

; Fork: Handle down
C381EA:  LDA $0B         ; Semi-auto keys
         BIT #$04        ; Pushing down?
         BEQ C38210      ; Branch if not
         LDA $54         ; Bottom menu row
         DEC A           ; Adjust value
         CMP $4E         ; Cursor's there?
         BNE C38209      ; Go down if not
         LDA $4A         ; Scroll position
         CMP $5C         ; At very bottom?
         BEQ C38206      ; Exit if so
         INC $50         ; List row +1
         JSR C3829E      ; Queue scrolling
         JSR C30EA3      ; Sound: Cursor
         RTS

; Fork: Exit
C38206:  JMP C38285      ; RTS...

; Fork: Move cursor down
C38209:  INC $50         ; List row +1
         INC $4E         ; Cursor row +1
         JSR C30EA3      ; Sound: Cursor

; Fork: Handle left
C38210:  LDA $0B         ; Semi-auto keys
         BIT #$02        ; Pushing left?
         BEQ C38249      ; Branch if not
         LDA $4D         ; On first column?
         BNE C38241      ; Branch if not
         LDA $4E         ; On top row?
         BEQ C3822D      ; Branch if so
         DEC $4E         ; Cursor row -1
         DEC $50         ; List row -1
         LDA $53         ; Furthest column
         DEC A           ; Adjust value
         STA $4D         ; Set as cursor's
         STA $4F         ; Set as list's
         JSR C30EA3      ; Sound: Cursor
         RTS

; Fork: Wrap to upper, offscreen row
C3822D:  LDA $4A         ; At top of list?
         BEQ C381C6      ; Exit if so
         JSR C38286      ; Queue scrolling
         LDA $53         ; Furthest column
         DEC A           ; Adjust value
         STA $4D         ; Set as cursor's
         STA $4F         ; Set as list's
         DEC $50         ; List row -1
         JSR C30EA3      ; Sound: Cursor
         RTS

; Fork: Move cursor left
C38241:  DEC $4D         ; Cursor column -1
         DEC $4F         ; List column -1
         JSR C30EA3      ; Sound: Cursor
         RTS

; Fork: Handle right
C38249:  LDA $0B         ; Semi-auto keys
         BIT #$01        ; Pushing right?
         BEQ C38285      ; Exit if not
         LDA $53         ; Furthest column
         DEC A           ; Adjust value
         CMP $4D         ; Cursor's there?
         BNE C3827E      ; Go right if not
         LDA $54         ; Bottom menu row
         DEC A           ; Adjust value
         CMP $4E         ; Cursor's there?
         BEQ C3826A      ; Branch if so
         TDC             ; Clear A
         STA $4D         ; Cursor column: 1
         STA $4F         ; List column: 1
         INC $4E         ; Cursor row +1
         INC $50         ; List row +1
         JSR C30EA3      ; Sound: Cursor
         RTS

; Fork: Wrap to lower, offscreen row
C3826A:  LDA $4A         ; Scroll position
         CMP $5C         ; At very bottom?
         BEQ C38285      ; Exit if so
         JSR C3829E      ; Queue scrolling
         TDC             ; Clear A
         STA $4D         ; Cursor column: 1
         STA $4F         ; List column: 1
         INC $50         ; List row +1
         JSR C30EA3      ; Sound: Cursor
         RTS

; Fork: Move cursor right
C3827E:  INC $4D         ; Cursor column +1
         INC $4F         ; List column +1
         JSR C30EA3      ; Sound: Cursor
C38285:  RTS

; Set to scroll list upward, draw row to scroll into view
C38286:  DEC $4A         ; Scroll pos -1
         DEC $49         ; Top BG1 row -1
         JSR C383F7      ; Define $E5, $E6
         JSR C382DD      ; Draw new row
         LDA #$00        ; Min slot: 0
         LDY #C38183     ; C3/8183
         JSR C31173      ; Queue scroll fn
         TDC             ; Anim mode: Up
         STA $7E3649,X   ; Set scroll mode
         RTS

; Set to scroll list downward, draw row to scroll into view
C3829E:  LDA $4212       ; PPU status
         AND #$40        ; H-Blank?
         BEQ C3829E      ; Loop if not
         LDA $5A         ; Rows per page
         CLC             ; Prepare ADC
         ADC $4A         ; Add scroll pos
         STA $211B       ; Set matrix A LB
         STZ $211B       ; Clear HB
         LDA $5B         ; Number of columns
         STA $211C       ; Set matrix B
         STA $211C       ; ...
         LDA $2134       ; Product LB
         STA $E5         ; Set SW list slot
         LDA $49         ; Top BG1 write row
         CLC             ; Prepare ADC
         ADC $5A         ; Get bottom row +1
         ASL A           ; x2 for blank rows
         AND #$1F        ; Stay in limits
         STA $E6         ; Set BG1 write row
         INC $4A         ; Scroll pos +1
         INC $49         ; Top BG1 row +1
         JSR C382DD      ; Draw new row
         LDA #$00        ; Min slot: 0
         LDY #C38183     ; C3/8183
         JSR C31173      ; Queue scroll fn
         LDA #$01        ; Anim mode: Down
         STA $7E3649,X   ; Set scroll mode
         RTS

; Draw list elements to scroll into view
C382DD:  TDC             ; Clear A
         LDA $2A         ; List type
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C382E5,X)  ; Draw row

; Jump table for the above
C382E5:  dw C37FA1       ; Inventory
         dw C34F9E       ; Magic
         dw C35256       ; Lore
         dw C353EE       ; Rage
         dw C354E3       ; Esper
         dw C39CE2       ; Gear

; Load common item's description and draw item count in Item menu
C382F1:  JSR C38308      ; Set desc ptrs
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         TAY             ; Index it
         LDA $1869,Y     ; Item in slot
         JSR C35738      ; Load description
         JSR C38356      ; Count items
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         JMP C3837A      ; Draw item count

; Prepare item description loading
C38308:  LDX #$7AA0      ; ED/7AA0
         STX $E7         ; Set ptr loc LBs
         LDX #$6400      ; ED/6400
         STX $EB         ; Set text loc LBs
         LDA #$ED        ; Bank: ED
         STA $E9         ; Set ptr loc HB
         LDA #$ED        ; ...
         STA $ED         ; Set text loc HB
         LDX #$9EC9      ; 7E/9EC9
         STX $2181       ; Set WRAM LBs
         RTS

; Compute item data index
C38321:  PHA             ; Save item
C38322:  LDA $4212       ; PPU status
         AND #$40        ; H-Blank?
         BEQ C38322      ; Loop if not
         PLA             ; Item
         STA $211B       ; Set matrix A LB
         STZ $211B       ; Clear HB
         LDA #$1E        ; Item data size
         STA $211C       ; Set matrix B
         STA $211C       ; ...
         RTS

; Load rare item's description and draw item count
C38339:  LDX #$FB60      ; CE/FB60
         STX $E7         ; Set ptr loc LBs
         LDX #$FCB0      ; CE/FCB0
         STX $EB         ; Set text loc LBs
         LDA #$CE        ; Bank: CE
         STA $E9         ; Set ptr loc HB
         STA $ED         ; Set text loc HB
         JSR C3572A      ; Load description
         JSR C3836B      ; Count items
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         JMP C3837A      ; Draw item count

; Count number of common items
C38356:  TDC             ; Clear A
         TAX             ; Item slot: 1
         TAY             ; Item count: 0
C38359:  LDA $1869,X     ; Item in slot
         CMP #$FF        ; None?
         BEQ C38361      ; Exclude if so
         INY             ; Item count +1
C38361:  INX             ; Item slot +1
         CPX #$0100      ; Done all 256?
         BNE C38359      ; Loop if not
         TYA             ; Get counter
         STA $64         ; Set item count
         RTS

; Count number of rare items
C3836B:  TDC             ; Clear A
         TAX             ; Item slot: 1
C3836D:  LDA $7E9D89,X   ; Empty slot?
         BMI C38376      ; Branch if so
         INX             ; Item slot +1
         BRA C3836D      ; Check next slot
C38376:  TXA             ; Current slot
         STA $64         ; Set item count
         RTS

; Draw number of common or rare items
C3837A:  LDA $64         ; Item count
         JSR C304E0      ; Turn into text
         LDX #$7ABF      ; Text position
         JMP C304C0      ; Draw 3 digits

; Blank item count in corner of Item menu
C38385:  LDY #C38E4A     ; Text pointer
         JMP C302F9      ; Draw 3 spaces

; Build and draw rare item list
C3838B:  JSR C36A15      ; Clear BG1 map A
         JSR C38394      ; Build item list
         JMP C383DE      ; Draw item list

; Build rare item list
C38394:  LDX #$9D89      ; 7E/9D89
         STX $2181       ; Set WRAM LBs
         LDY #$0014      ; Items: 20
         LDA #$FF        ; Empty item
C3839F:  STA $2180       ; Add to list
         DEY             ; One less left
         BNE C3839F      ; Loop till last
         LDX #$9D89      ; ...
         STX $2181       ; Reset WRAM LBs
         LDX $1EBA       ; Item packs A+B
         STX $EF         ; Memorize them
         LDA $1EBC       ; Item pack C
         STA $F1         ; Memorize it
         LDA $1EBD       ; ...
         AND #$0F        ; ...
         STZ $F2         ; Clear pack D
         TDC             ; Item: Cider
         STA $E0         ; Set as current
         TAX             ; Pack index: 0
         LDA #$04        ; Item packs: 4
         STA $E1         ; Set counter
C383C4:  LDY #$0008      ; Items left: 8
         LDA $EF,X       ; 8 owned items
C383C9:  ROR A           ; Got current?
         PHA             ; Save item pack
         BCC C383D2      ; Skip if not
         LDA $E0         ; Item number
         STA $2180       ; Add to list
C383D2:  INC $E0         ; Item number +1
         PLA             ; 8 owned items
         DEY             ; One less item
         BNE C383C9      ; Loop till last
         INX             ; Pack index +1
         DEC $E1         ; One less pack
         BNE C383C4      ; Loop till last
         RTS

; Draw rare item list
C383DE:  JSR C383F7      ; Define $E6
         STZ $E5         ; Item slot: 1
         LDY #$000A      ; Rows left: 10
C383E6:  PHY             ; Save counter
         JSR C3841B      ; Draw 2 items
         LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         INC A           ; Go 1 row down
         AND #$1F        ; Stay in limits
         STA $E6         ; Save changes
         PLY             ; Rows left
         DEY             ; One less left
         BNE C383E6      ; Loop till last
         RTS

; Define BG1 row for drawing list, plus first onscreen list slot
C383F7:  LDA $49         ; Top BG1 write row
         ASL A           ; x2 for blank rows
         AND #$1F        ; Stay in limits
         STA $E6         ; Set BG1 write row
C383FE:  LDA $4212       ; PPU status
         AND #$40        ; H-Blank?
         BEQ C383FE      ; Loop if not
         LDA $4A         ; Scroll position
         STA $211B       ; Set matrix A LB
         STZ $211B       ; Clear HB
         LDA $5B         ; Number of columns
         STA $211C       ; Set matrix B
         STA $211C       ; ...
         LDA $2134       ; Product LB
         STA $E5         ; Set list slot
         RTS

; Draw a row of two rare items
C3841B:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         JSR C38436      ; Define source
         LDX #$0003      ; X: 3
         JSR C38445      ; Draw item A
         INC $E5         ; Item slot +1
         JSR C38436      ; Define source
         LDX #$0011      ; X: 17
         JSR C38445      ; Draw item B
         INC $E5         ; Item slot +1
         RTS

; Set source for loading rare item name
C38436:  LDY #$000D      ; Letters: 13
         STY $EB         ; Set src size
         LDY #$FBA0      ; CE/FBA0
         STY $EF         ; Set src LBs
         LDA #$CE        ; Bank: CE
         STA $F1         ; Set src HB
         RTS

; Draw rare item name
C38445:  LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         JSR C3809F      ; Compute map ptr
         REP #$20        ; 16-bit A
         TXA             ; ...
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $E5         ; Item slot
         TAX             ; Index it
         LDA $7E9D89,X   ; Item in slot
         CMP #$FF        ; None?
         BEQ C38466      ; Exit if so
         JSR C38467      ; Load name
         JMP C37FD9      ; Draw name
C38466:  RTS

; Load fixed-size string from table
C38467:  PHA             ; Save name ID
         LDX #$9E8B      ; 7E/9E8B
         STX $2181       ; Set WRAM LBs
C3846E:  LDA $4212       ; PPU status
         AND #$40        ; H-Blank?
         BEQ C3846E      ; Loop if not
         PLA             ; Name number
         STA $211B       ; Set matrix A LB
         STZ $211B       ; Clear HB
         TDC             ; Clear A
         LDA $EB         ; String size
         STA $211C       ; Set matrix B
         STA $211C       ; ...
         LDY $2134       ; Index product
         LDX $EB         ; String size
C3848A:  LDA [$EF],Y     ; Letter
         STA $2180       ; Add to string
         INY             ; Point to next
         DEX             ; One less left
         BNE C3848A      ; Loop till last
         STZ $2180       ; End string
         RTS

; Handle double-clicked item
C38497:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
         STA $28         ; Set blinker's
         TAY             ; Index it
         LDA $1869,Y     ; Selected item
         CMP #$FF        ; Empty slot?
         BEQ C38510      ; Fail if so
         CMP #$EF        ; Megalixir?
         BEQ C38510      ; Fail if so...
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85000,X   ; Item properties
         AND #$07        ; Get item class
         CMP #$06        ; Consumable?
         BNE C38515      ; Branch if not
         LDA $D85000,X   ; Item properties
         AND #$40        ; Usable in field?
         BEQ C38510      ; Fail if not
         TDC             ; ...
         LDA $28         ; Selected slot
         TAY             ; Index it
         LDA $1869,Y     ; Item in slot
         CMP #$F7        ; Tent?
         BEQ C384F8      ; Branch if so
         CMP #$F6        ; Sleeping Bag?
         BEQ C384E2      ; Branch if so
         CMP #$FD        ; Warp Stone?
         BEQ C384EB      ; Branch if so
C384D3:  LDY $4F         ; Cursor position
         STY $8E         ; Set return loc
         LDA $4A         ; Scroll position
         STA $90         ; Set return loc
         LDA #$6F        ; C3/8A84
         STA $27         ; Queue usage menu
         STZ $26         ; Next: Fade-out
         RTS

; Fork: Sleeping Bag
C384E2:  STA $E6         ; Memorize item
         LDA $0201       ; Can save here?
         BPL C38510      ; Fail if not
         BRA C384D3      ; Queue usage menu

; Fork: Warp Stone
C384EB:  STA $E6         ; Memorize item
         LDA $0201       ; Area permissions
         BIT #$02        ; Can warp here?
         BEQ C38510      ; Fail if not
         LDA #$03        ; Event: Warp
         BRA C38501      ; Destroy item

; Fork: Tent
C384F8:  STA $E6         ; Memorize item
         LDA $0201       ; Can save here?
         BPL C38510      ; Fail if not
         LDA #$02        ; Event: Tent
C38501:  STA $0205       ; Set aftereffect
         LDA $E6         ; Item
         JSR C39D97      ; Destroy it
         LDA #$FF        ; Null value
         STA $27         ; Queue menu exit
         STZ $26         ; Next: Fade-out
         RTS

; Fork: Unusable consumable
C38510:  LDA #$08        ; C3/1EF7
         STA $26         ; Next: Choice 1
         RTS

; Fork: Compile gear's compatible actors
C38515:  LDY #$9D89      ; 7E/9D89
         STY $2181       ; Set WRAM LBs
         CMP #$00        ; Tool class?
         BEQ C38510      ; Abort if so
         STZ $E0         ; Current: Terra
         REP #$20        ; 16-bit A
         LDA $D85001,X   ; Compatibility
         LDX $00         ; Actors done: 0
C38529:  LSR A           ; Actor can use?
         BCC C38537      ; Skip if not
         PHA             ; Save compat.
         SEP #$20        ; 8-bit A
         LDA $E0         ; Current actor
         STA $2180       ; Add to list
         REP #$20        ; 16-bit A
         PLA             ; Compatibility
C38537:  SEP #$20        ; 8-bit A
         INC $E0         ; Actor number +1
         REP #$20        ; 16-bit A
         INX             ; Actors done +1
         CPX #$000E      ; Done all 14?
         BNE C38529      ; Loop if not
         SEP #$20        ; 8-bit A
         LDA #$FF        ; Terminator
         STA $2180       ; End list

; Fork: Initialize gear data menu
C3854A:  REP #$20        ; 16-bit A
         LDA #$00E0      ; BG1 H-Shift: 224
         STA $7E9A10     ; Hide item list
         LDA #$7D8D      ; Tilemap ptr
         STA $7E9E89     ; Set item pos
         SEP #$20        ; 8-bit A
         LDA #$04        ; Cursor: Blank
         TRB $45         ; Set menu flag
         JSR C3858C      ; Stop desc/bar
         JSR C38595      ; Create arrow
         TDC             ; ...
         LDA $4B         ; Item's slot
         TAY             ; Index it
         JSR C380B9      ; Load "<item>:"
         JSR C385AD      ; Add "can be..."
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         JSR C37FD9      ; Draw string
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         JSR C385D5      ; Draw actor list
         JSR C38671      ; Draw other info
         JSR C30F25      ; Queue text upload
         JSR C30F89      ; Dequeue desc DMA
         LDA #$64        ; C3/8983
         STA $26         ; Next: Sustain menu
         RTS

; Disable scrollbar and freeze description
C3858C:  LDA #$C0        ; Scrollbar: Off
         TRB $46         ; Set anim index
         LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         RTS

; Create arrow for gear data menu
C38595:  LDA #$01        ; Status: On
         STA $99         ; Enable arrow
         LDA #$01        ; Min slot: 8
         LDY #C37A19     ; C3/7A19
         JSR C31173      ; Queue OAM fn
         LDA #$80        ; Y: 128
         STA $7E344A,X   ; Set sprite's
         TDC             ; ...
         STA $7E344B,X   ; No use...
         RTS

; Add " can be used by:" after item name
C385AD:  LDX #$0001      ; Skip item icon
C385B0:  LDA $7E9E8B,X   ; Item letter
         CMP #$FF        ; Terminator?
         BNE C385CD      ; Branch if not
C385B8:  LDY $00         ; ROM index: 0
C385BA:  PHX             ; Save RAM index
         TYX             ; ROM index
         LDA.L C38D34,X  ; Message letter
         PLX             ; RAM index
         STA $7E9E8B,X   ; Add to string
         INX             ; RAM index +1
         INY             ; ROM index +1
         CPY #$0011      ; Done 17 chars?
         BNE C385BA      ; Loop if not
         RTS

; Fork: Check next letter from item name
C385CD:  INX             ; RAM index +1
         CPX #$000D      ; Done 12 chars?
         BNE C385B0      ; Loop if not
         BRA C385B8      ; Load "can..."

; Filter and draw gear's list of compatible actors
C385D5:  LDX #$9E09      ; 7E/9E09
         STX $2181       ; Set WRAM LBs
         LDX $00         ; List slot: 1
C385DD:  LDA $7E9D89,X   ; Eligible actor
         BMI C38623      ; Branch if end
         STA $E5         ; Memorize actor
         LDY $00         ; Actor slot: 1
         STY $E7         ; Save actor slot

; Fork: Exclude if never recruited or dead Shadow
C385E9:  STX $F3         ; Save list slot
         LDA $E5         ; Eligible actor
         CMP $1600,Y     ; In actor slot?
         BNE C3860A      ; Try next if not
         REP #$20        ; 16-bit A
         LDA $E7         ; Actor slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA $1EDC       ; Showable actors
         AND.L C39C67,X  ; Has our actor?
         SEP #$20        ; 8-bit A
         BEQ C3861B      ; Skip if not
         LDA $E7         ; Actor slot
         STA $2180       ; Add to new list
         BRA C3861B      ; Do next actor

; Fork: Try next actor in SRAM block
C3860A:  REP #$21        ; 16-bit A; C-
         TYA             ; Actor's address
         ADC #$0025      ; Point to next
         TAY             ; Reindex it
         SEP #$20        ; 8-bit A
         INC $E7         ; Actor slot +1
         LDA $E7         ; Actor slot
         CMP #$10        ; Done all 16?
         BNE C385E9      ; Loop if not

; Fork: Handle next eligible actor
C3861B:  LDX $F3         ; List slot
         INX             ; List slot +1
         CPX #$0010      ; Done all 16?
         BNE C385DD      ; Loop if not

; Fork: End and draw new list
C38623:  LDA #$FF        ; Terminator
         STA $2180       ; End list
         LDX $00         ; List slot: 1
C3862A:  TDC             ; Clear A
         LDA $7E9E09,X   ; Actor in slot
         BMI C38652      ; Exit if none
         PHX             ; Save slot
         PHX             ; Save slot
         REP #$20        ; 16-bit A
         ASL A           ; Actor x2
         TAX             ; Index it
         LDA.L C36969,X  ; Actor address
         STA $67         ; Memorize it
         PLX             ; List slot
         TXA             ; Put in A
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C38653,X  ; Position
         TAY             ; Put in Y
         SEP #$20        ; 8-bit A
         JSR C334CF      ; Draw name
         PLX             ; List slot
         INX             ; List slot +1
         CPX #$000E      ; Done all 14?
         BNE C3862A      ; Loop if not
C38652:  RTS

; Text positions for gear data menu
C38653:  dw $7E0F        ; Actor name 1
         dw $7E23        ; Actor name 2
         dw $7E37        ; Actor name 3
         dw $7E8F        ; Actor name 4
         dw $7EA3        ; Actor name 5
         dw $7EB7        ; Actor name 6
         dw $7F0F        ; Actor name 7
         dw $7F23        ; Actor name 8
         dw $7F37        ; Actor name 9
         dw $7F8F        ; Actor name 10
         dw $7FA3        ; Actor name 11
         dw $7FB7        ; Actor name 12
         dw $800F        ; Actor name 13
         dw $8023        ; Actor name 14
         dw $8037        ; Actor name 15 (unused)

; Draw all gear info except compatible actors
C38671:  JSR C36A41      ; Clear BG3 map B
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         LDX #C38D45     ; Text ptrs loc
         LDY #$001C      ; Strings: 14
         JSR C369BA      ; Draw Vigor, etc.
         LDA #$2C        ; ...
         STA $29         ; ...
         LDX #C38D61     ; Text ptrs loc
         LDY #$0008      ; Strings: 4
         JSR C369BA      ; Draw Speed, etc.

; Fork: Draw stat modifiers
C3868E:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         TDC             ; Clear A
         LDA $4B         ; Selected slot
         TAY             ; Index it
         LDA $1869,Y     ; Item in slot
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         TDC             ; Terminator
         STA $7E9E8D     ; Set mod B3
         STA $7E9E8E     ; Set mod B4
         REP #$20        ; 16-bit A
         LDA #$8445      ; Tilemap ptr
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $D85010,X   ; Stat mods LB
         PHA             ; Memorize them
         AND #$0F        ; Vigor index
         ASL A           ; Double it
         JSR C38836      ; Draw modifier
         REP #$20        ; 16-bit A
         LDA #$84C5      ; Tilemap ptr
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         PLA             ; Stat mods LB
         AND #$F0        ; Speed index
         LSR A           ; Put in b3-b6
         LSR A           ; Put in b2-b5
         LSR A           ; Put in b1-b4
         JSR C38836      ; Draw modifier
         REP #$20        ; 16-bit A
         LDA #$8545      ; Tilemap ptr
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         LDX $2134       ; Item index
         TDC             ; Clear A
         LDA $D85011,X   ; Stats mods HB
         PHA             ; Memorize them
         AND #$0F        ; Stamina index
         ASL A           ; Double it
         JSR C38836      ; Draw modifier
         REP #$20        ; 16-bit A
         LDA #$85C5      ; Tilemap ptr
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         PLA             ; Stat mods HB
         AND #$F0        ; Mag.Pwr index
         LSR A           ; Put in b3-b6
         LSR A           ; Put in b2-b5
         LSR A           ; Put in b1-b4
         JSR C38836      ; Draw modifier

; Fork: Draw defensive properties
C38703:  LDX $2134       ; Item index
         LDA $D85000,X   ; Properties
         AND #$07        ; Get class
         CMP #$01        ; Weapon?
         BEQ C38746      ; Branch if so
         LDA $D85014,X   ; Defense
         JSR C304E0      ; Turn into text
         LDX #$86C3      ; Text position
         JSR C304C0      ; Draw 3 digits
         LDX $2134       ; Item index
         LDA $D85015,X   ; Mag.Def
         JSR C304E0      ; Turn into text
         LDX #$87C3      ; Text position
         JSR C304C0      ; Draw 3 digits
         JSR C387EB      ; Draw evasions
         JSR C388A0      ; Draw 50% elems
         JSR C38959      ; Draw other ones
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         LDX #C38D69     ; Text ptrs loc
         LDY #$0008      ; Strings: 4
         JSR C369BA      ; Draw elem types
         JMP C387C7      ; Do spell taught

; Fork: Draw offensive properties
C38746:  JSR C3879C      ; Draw Bat.Pwr
         JSR C387EB      ; Draw evasions
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         LDY #C38E1D     ; Text pointer
         JSR C302F9      ; Draw "Attack"
         JSR C388A0      ; Draw elements
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDX $2134       ; Item index
         LDA $D85013,X   ; Allows Runic?
         BPL C3876E      ; Branch if not
         LDY #C38E30     ; Text pointer
         STY $E7         ; Set src LBs
         JSR C38795      ; Draw "Runic"
C3876E:  LDX $2134       ; Item index
         LDA $D85013,X   ; Properties
         AND #$40        ; 2-hand OK?
         BEQ C38781      ; Branch if not
         LDY #C38E38     ; Text pointer
         STY $E7         ; Set src LBs
         JSR C38795      ; Draw "2-hand"
C38781:  LDX $2134       ; Item index
         LDA $D85013,X   ; Properties
         AND #$02        ; Can SwdTech?
         BEQ C38794      ; Exit if not
         LDY #C38E26     ; Text pointer
         STY $E7         ; Set src LBs
         JSR C38795      ; Draw "SwdTech"
C38794:  RTS

; Draw string for the above
C38795:  LDA #$C3        ; Bank: C3
         STA $E9         ; Set src HB
         JMP C302FF      ; Draw text

; Draw weapon's Bat.Pwr in gear data menu
C3879C:  TDC             ; Clear A
         LDA $4B         ; Clicked slot
         TAY             ; Index it
         LDA $1869,Y     ; Item in slot
         CMP #$1C        ; Atma Weapon?
         BEQ C387C0      ; Hide if so
         CMP #$16        ; Soul Sabre?
         BEQ C387C0      ; Hide if so
         CMP #$51        ; Dice?
         BEQ C387C0      ; Hide if so
         CMP #$52        ; Fixed Dice?
         BEQ C387C0      ; Hide if so
         LDA $D85014,X   ; Bat.Pwr
         JSR C304E0      ; Turn into text
         LDX #$8643      ; Text position
         JMP C304C0      ; Draw 3 digits

; Fork: Hide power
C387C0:  LDY #C38D71     ; Text pointer
         JSR C302F9      ; Draw "???"
         RTS

; Draw spell taught by armor, including learning rate
C387C7:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDX $2134       ; Item index
         LDA $D85003,X   ; Learning rate
         BEQ C387EA      ; Exit if 0
         STA $E0         ; Memorize it
         LDA $D85004,X   ; Spell taught
         STA $E1         ; Memorize it
         REP #$20        ; 16-bit A
         LDA #$832F      ; Tilemap ptr
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         JSR C35AED      ; Draw string
C387EA:  RTS

; Draw Evade and MBlock modifiers for gear data menu
C387EB:  REP #$20        ; 16-bit A
         LDA #$8743      ; Tilemap ptr
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         LDX $2134       ; Item index
         TDC             ; Clear A
         LDA $D8501A,X   ; Evasion mods
         PHA             ; Memorize them
         AND #$0F        ; Evade index
         ASL A           ; x2
         ASL A           ; x4
         JSR C3881A      ; Draw modifier
         REP #$20        ; 16-bit A
         LDA #$8843      ; Tilemap ptr
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         LDX $2134       ; Item index
         TDC             ; Clear A
         PLA             ; Evasion mods
         AND #$F0        ; MBlock index
         LSR A           ; ÷2
         LSR A           ; ÷4
C3881A:  TAX             ; Index it
         LDA.L C38854,X  ; Sign
         STA $7E9E8B     ; Add to string
         LDA.L C38854+1,X; Tens digit
         STA $7E9E8C     ; Add to string
         LDA.L C38854+2,X; Ones digit
         STA $7E9E8D     ; Add to string
         JMP C38847      ; Draw modifier

; Draw a non-evasion stat modifier for gear data menu
C38836:  TAX             ; Modifier index
         LDA.L C38880,X  ; Sign
         STA $7E9E8B     ; Add to string
         LDA.L C38880+1,X; Digit
         STA $7E9E8C     ; Add to string
C38847:  LDY #$9E89      ; 7E/9E89
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         JSR C302FF      ; Draw modifier
         RTS

; Text for evasion modifiers
C38854:  db "  0",$00
         db "+10",$00
         db "+20",$00
         db "+30",$00
         db "+40",$00
         db "+50",$00
         db "-10",$00
         db "-20",$00
         db "-30",$00
         db "-40",$00
         db "-50",$00

; Text for non-evasion stat modifiers
C38880:  db " 0"
         db "+1"
         db "+2"
         db "+3"
         db "+4"
         db "+5"
         db "+6"
         db "+7"
         db " 0"         ; Unused
         db "-1"
         db "-2"
         db "-3"
         db "-4"
         db "-5"
         db "-6"
         db "-7"

; Build and draw list of attack or halved elements
C388A0:  LDX $2134       ; Item index
         TDC             ; ...
         LDA $D8500F,X   ; Elements
         JSR C388AE      ; Build list
         JMP C388CE      ; Draw list

; Build current list of elements
C388AE:  LDY #$AA8D      ; 7E/AA8D
         STY $2181       ; Set WRAM LBs
         STZ $E0         ; Current: Water
         LDY #$0008      ; Elements: 8
C388B9:  ROL A           ; Draw current?
         BCC C388C3      ; Skip it if not
         PHA             ; Save elements
         LDA $E0         ; Current element
         STA $2180       ; Add to list
         PLA             ; Elements left
C388C3:  INC $E0         ; Elem number +1
         DEY             ; One less left
         BNE C388B9      ; Loop till last
         LDA #$FF        ; Terminator
         STA $2180       ; End list
         RTS

; Draw list of attack or halved elements
C388CE:  LDX #$7BCD      ; Tilemap ptr
         STX $EB         ; Set dest LBs
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set dest HB
         JMP C388FE      ; Draw list

; Draw list of absorbed elements
C388DA:  LDX #$7BE9      ; Tilemap ptr
         STX $EB         ; Set dest LBs
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set dest HB
         JMP C388FE      ; Draw list

; Draw list of nulled elements
C388E6:  LDX #$7CCD      ; Tilemap ptr
         STX $EB         ; Set dest LBs
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set dest HB
         JMP C388FE      ; Draw list

; Draw list of elemental weaknesses
C388F2:  LDX #$7CE9      ; Tilemap ptr
         STX $EB         ; Set dest LBs
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set dest HB
         JMP C388FE      ; ...

; Draw current list of elements
C388FE:  TDC             ; Clear A
         TAX             ; Index: 0
C38900:  TDC             ; Clear A
         LDA $7EAA8D,X   ; Element to draw
         BMI C38926      ; Exit if no more
         PHX             ; Save list index
         REP #$20        ; 16-bit A
         ASL A           ; Element x2
         TAX             ; Index it
         LDA.L C38927,X  ; Tilemap data
         STA $E0         ; Memorize it
         JSR C38937      ; Draw element
         LDA $EB         ; Tilemap ptr
         CLC             ; ...
         ADC #$0004      ; Skip 2 tiles
         STA $EB         ; Save changes
         SEP #$20        ; 8-bit A
         PLX             ; List index
         INX             ; List index +1
         CPX #$0006      ; Done 6 entries?
         BNE C38900      ; Loop if not
C38926:  RTS

; Base tile attributes for each element
C38927:  dw $3580        ; Water
         dw $3584        ; Earth
         dw $3588        ; Pearl
         dw $358C        ; Wind
         dw $3590        ; Poison
         dw $3594        ; Lightning
         dw $3598        ; Ice
         dw $359C        ; Fire

; Draw current element
C38937:  TDC             ; Clear A
         TAY             ; Map ptr: NW
         LDA $E0         ; Attributes
         STA [$EB],Y     ; Set NW tile
         INC $E0         ; Tile num +1
         LDY #$0040      ; Map ptr: SW
         LDA $E0         ; Attributes
         STA [$EB],Y     ; Set SW tile
         INC $E0         ; Tile num +1
         LDY #$0002      ; Map ptr: NE
         LDA $E0         ; Attributes
         STA [$EB],Y     ; Set NE tile
         INC $E0         ; Tile num +1
         LDY #$0042      ; Map ptr: SE
         LDA $E0         ; Attributes
         STA [$EB],Y     ; Set SE tile
         RTS

; Build and draw list of absorbed, nulled, and weak elements
C38959:  LDX $2134       ; Item index
         TDC             ; ...
         LDA $D85016,X   ; Absorbed elements
         JSR C388AE      ; Build list
         JSR C388DA      ; Draw list
         LDX $2134       ; Item index
         TDC             ; ...
         LDA $D85017,X   ; Nulled elements
         JSR C388AE      ; Build list
         JSR C388E6      ; Draw list
         LDX $2134       ; Item index
         TDC             ; ...
         LDA $D85018,X   ; Weak points
         JSR C388AE      ; Build list
         JMP C388F2      ; Draw list

; 64: Sustain non-shifted gear data menu
C38983:  LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BNE C3898F      ; Branch if so
         LDA $09         ; No-autofire keys
         BIT #$02        ; Pushing left?
         BEQ C389A8      ; Branch if not
C3898F:  JSR C30EB2      ; Sound: Click
         LDA #$FF        ; Status: Off
         STA $99         ; Disable arrow
         LDA #$0A        ; Frames: 10
         STA $20         ; Set scroll timer
         LDY #$FFF4      ; Speed: -12
         STY $9C         ; Set scroll speed
         LDA #$5E        ; C3/89E6
         STA $27         ; Queue: Moved menu
         LDA #$65        ; C3/36E7
         STA $26         ; Next: Pan screen
         RTS

; Fork: Handle B
C389A8:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C389DD      ; Exit if not
         JSR C30EA9      ; Sound: Cursor
         LDA #$FF        ; Status: Off
         STA $99         ; Disable arrow
         LDX #$7B49      ; 7E/7B49
         STX $2181       ; Set WRAM LBs
         LDX #$0280      ; BG3 tiles: 640
C389BE:  STZ $2180       ; Clear tile LB
         STZ $2180       ; Clear tile HB
         DEX             ; One less tile
         BNE C389BE      ; Loop till last
         LDA #$04        ; Show cursor: Y
         TSB $45         ; Set menu flag
         JSR C389DE      ; Desc/Bar: On
         JSR C30F39      ; Queue BG3 upload
         JSR C31368      ; Upload it now
         TDC             ; BG1 H-Shift: 0
         STA $7E9A10     ; Unhide item list
         LDA #$08        ; C3/1EF7
         STA $26         ; Next: Choice 1
C389DD:  RTS

; Create scrollbar and set to update description
C389DE:  JSR C3091F      ; Create scrollbar
         LDA #$10        ; Description: On
         TRB $45         ; Set menu flag
         RTS

; 5E: Sustain shifted gear data menu
C389E6:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BNE C389F2      ; Branch if so
         LDA $09         ; ...
         BIT #$01        ; Pushing right?
         BEQ C38A0D      ; Exit if not
C389F2:  JSR C30EA9      ; Sound: Cursor
         LDA #$0A        ; Frames: 10
         STA $20         ; Set scroll timer
         LDY #$000C      ; Speed: 12
         STY $9C         ; Set scroll speed
         LDA #$05        ; Blinker: Off...
         TRB $46         ; Set menu flag
         LDA #$64        ; C3/8983
         STA $27         ; Queue screen 1
         LDA #$65        ; C3/36E7
         STA $26         ; Next: Pan screen
         JSR C38595      ; Create arrow
C38A0D:  RTS

; Draw item usage menu
C38A0E:  JSR C36A28      ; Clear BG2 map A
         LDY #C38A3B     ; C3/8A3B
         JSR C30341      ; Draw party box
         LDY #C38A3F     ; C3/8A3F
         JSR C30341      ; Draw item box
         LDY #C38A43     ; C3/8A43
         JSR C30341      ; Draw quantity box
         JSR C30E52      ; Upload windows
         JSR C36A19      ; Clear BG1 map B
         LDY #$FFC0      ; X: -64 = 448
         STY $35         ; Set BG1 X-Pos
         LDA #$02        ; Portrait row bit
         TSB $45         ; Ignore back row
         JSR C3318A      ; Draw party info
         JSR C38A47      ; Draw item info
         JMP C3319F      ; Upload text maps

; Window layout for item usage menu
C38A3B:  dw $589D,$1813  ; 21x26 at $589D (Party)
C38A3F:  dw $588B,$020D  ; 15x04 at $588B (Item)
C38A43:  dw $598B,$0307  ; 09x05 at $598B (Quantity)

; Draw item info for item usage menu
C38A47:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDY #C38E41     ; Text pointer
         JSR C302F9      ; Draw "Owned:"
         REP #$20        ; 16-bit A
         LDA #$790B      ; Tilemap ptr
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $4B         ; Item's slot
         TAY             ; Index it
         JSR C380B9      ; Load "<item>:"
         TDC             ; Terminator
         STA $7E9E98     ; Remove ":"
         JSR C37FD9      ; Draw item
         BRA C38A6D      ; ...

; Draw quantity owned for item usage menu
C38A6D:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         TDC             ; Clear A
         LDA $28         ; Item's slot
         TAY             ; Index it
         LDA $1969,Y     ; Item quantity
         JSR C304E0      ; Turn into text
         LDX #$7A93      ; Text position
         JSR C304B6      ; Draw 2 digits
         JMP C37FD9      ; Redraw item...

; 6F: Initialize item usage menu
C38A84:  JSR C32A76      ; Init variables
         JSR C38A0E      ; Draw menu
         JSR C307B0      ; Queue cursor OAM
         LDA #$40        ; No cursor memory
         TSB $45         ; Set menu flag
         LDA #$70        ; Queue: Sustain menu
         JMP C32AA5      ; Next: Fade-in

; 70: Sustain item usage menu
C38A96:  JSR C30EFD      ; Queue stats upload
         JSR C30F61      ; And item info's
         LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C38AAC      ; Branch if not
         JSR C38C2B      ; Item
         CMP #$E7        ; Rename Card?
         BEQ C38AC0      ; Branch if so
         JSR C38AE7      ; Handle item usage

; Fork: Handle B
C38AAC:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C38ABF      ; Exit if not
         JSR C30EA9      ; Sound: Cursor
C38AB5:  LDA #$42        ; Allow back row
         TRB $45         ; And cursor memory
         LDA #$77        ; C3/1B35
         STA $27         ; Queue Item menu
         STZ $26         ; Next: Fade-out
C38ABF:  RTS

; Fork: Rename Card
C38AC0:  JSR C32D0B      ; Define Y
         LDA $0000,Y     ; Actor
         CMP #$0E        ; Guest?
         BCS C38AE0      ; Fail if so
         STY $0206       ; Save actor adr
         JSR C30EB2      ; Sound: Click
         LDA #$FE        ; Actor renaming
         STA $0205       ; Set next menu
         LDA #$FF        ; Null value
         STA $27         ; Queue menu exit
         STZ $26         ; Next: Fade-out
         LDA #$E7        ; Item number
         JMP C39D97      ; Destroy item

; Fork: Prevent guest renaming
C38AE0:  JSR C30EC0      ; Play buzzer
         JSR C3305D      ; Pixelate screen
         RTS

; Handle item usage, excluding Rename Card
C38AE7:  JSR C38C2B      ; ...
         JSR C32D0B      ; Target's address
         JSR C38B3D      ; Valid target?
         BCC C38B0A      ; Fail if not
         JSR C30EE5      ; Play heal sound
         JSR C38B11      ; Heal & destroy
         JSR C38A6D      ; Redraw quantity
         JSR C32C01      ; Redraw party
         TDC             ; Clear A
         LDA $28         ; Item's slot
         TAY             ; Index it
         LDA $1969,Y     ; Item quantity
         BNE C38B10      ; Exit if not 0
         JMP C38AB5      ; Close submenu
C38B0A:  JSR C30EC0      ; Play buzzer
         JSR C3305D      ; Pixelate screen
C38B10:  RTS

; Heal item's target, destroy item
C38B11:  JSR C38B1A      ; Heal target
         JSR C38C2B      ; Selected item
         JMP C39D97      ; Destroy item

; Adjust item target's HP, MP, and status
C38B1A:  LDA $0014,Y     ; Status LB
         STA $F8         ; Set target's
         LDA $0015,Y     ; Status HB
         STA $FB         ; Set target's
         PHY             ; Save index
         JSR C38C2B      ; Item number
         LDX #$0002      ; Mode: Item
         JSL $C20009     ; Get new status
         PLY             ; Actor's address
         LDA $FC         ; Status LB
         STA $0014,Y     ; Set actor's
         LDA $FF         ; Status HB
         STA $0015,Y     ; Set actor's
         JMP C38C33      ; Heal HP & MP

; Determine whether item target is valid
C38B3D:  LDA $0014,Y     ; Status
         AND #$80        ; Wound?
         BNE C38B85      ; Branch if so
         JSR C38C2B      ; Item
         CMP #$FE        ; Dried Meat?
         BEQ C38BC4      ; Branch if so
         CMP #$E8        ; Tonic?
         BEQ C38BC4      ; Branch if so
         CMP #$E9        ; Potion?
         BEQ C38BC4      ; Branch if so
         CMP #$EA        ; X-Potion?
         BEQ C38BC4      ; Branch if so
         CMP #$EB        ; Tincture?
         BEQ C38BD5      ; Branch if so
         CMP #$EC        ; Ether?
         BEQ C38BD5      ; Branch if so
         CMP #$ED        ; X-Ether?
         BEQ C38BD5      ; Branch if so
         CMP #$F1        ; Revivify?
         BEQ C38B8E      ; Branch if so
         CMP #$F2        ; Antidote?
         BEQ C38BBB      ; Branch if so
         CMP #$F3        ; Eyedrop?
         BEQ C38B97      ; Branch if so
         CMP #$F4        ; Soft?
         BEQ C38BA0      ; Branch if so
         CMP #$F5        ; Remedy?
         BEQ C38BB2      ; Branch if so
         CMP #$EE        ; Elixir?
         BEQ C38BE5      ; Branch if so
         CMP #$F8        ; Green Cherry?
         BEQ C38BA9      ; Branch if so
         CMP #$F6        ; Sleeping Bag?
         BEQ C38BD2      ; Branch if so
         BRA C38BD0      ; Make item fail

; Fork: Fenix Down
C38B85:  JSR C38C2B      ; Item
         CMP #$F0        ; Fenix Down?
         BEQ C38BE3      ; Succeed if so
         BRA C38BD0      ; Make item fail

; Fork: Revivify
C38B8E:  LDA $0014,Y     ; Status
         AND #$02        ; Zombie?
         BEQ C38BD0      ; Fail if not
         BRA C38BE3      ; Make item work

; Fork: Eyedrop
C38B97:  LDA $0014,Y     ; Status
         AND #$01        ; Dark?
         BEQ C38BD0      ; Fail if not
         BRA C38BE3      ; Make item work

; Fork: Soft
C38BA0:  LDA $0014,Y     ; Status
         AND #$40        ; Petrify?
         BEQ C38BD0      ; Fail if not
         BRA C38BE3      ; Make item work

; Fork: Green Cherry
C38BA9:  LDA $0014,Y     ; Status
         AND #$20        ; Imp?
         BEQ C38BD0      ; Fail if not
         BRA C38BE3      ; Make item work

; Fork: Remedy
C38BB2:  LDA $0014,Y     ; Dark? Poison?
         AND #$65        ; Imp? Petrify?
         BEQ C38BD0      ; Fail if none
         BRA C38BE3      ; Make item work

; Fork: Antidote
C38BBB:  LDA $0014,Y     ; Status
         AND #$04        ; Poison?
         BEQ C38BD0      ; Fail if not
         BRA C38BE3      ; Make item work

; Fork: Dried Meat, Tonic, Potion, X-Potion
C38BC4:  LDA $0014,Y     ; Zombie? KO?
         AND #$C2        ; Or Petrify?
         BNE C38BD0      ; Fail if any
         JSR C32B9A      ; At full HP?
         BCC C38BE3      ; Succeed if not

; Fork: Make item fail
C38BD0:  CLC             ; Mark failure
         RTS

; Fork: Sleeping Bag (A)
C38BD2:  JMP C38C11      ; BRA...

; Fork: Tincture, Ether, X-Ether
C38BD5:  LDA $0014,Y     ; Zombie? KO?
         AND #$C2        ; Or Petrify?
         BNE C38BD0      ; Fail if any
         JSR C32BBC      ; At full MP?
         BCC C38BE3      ; Succeed if not
         BRA C38BD0      ; Make item fail

; Fork: Make item work
C38BE3:  SEC             ; Mark success
         RTS

; Fork: Elixir
C38BE5:  LDA $0014,Y     ; Zombie? KO?
         AND #$C2        ; Or Petrify?
         BNE C38BD0      ; Fail if any
         JSR C32B9A      ; At full HP?
         BCC C38BE3      ; Succeed if not
         JSR C32BBC      ; At full MP?
         BCC C38BE3      ; Succeed if not
         BRA C38BD0      ; Make item fail

; Fork: Megalixir (unused)
C38BF8:  TDC             ; Clear A
         TAX             ; Member index: 0
C38BFA:  STX $ED         ; Memorize index
         LDY $006D,X     ; Actor's address
         BEQ C38C06      ; Skip if nobody
         JSR C38BE5      ; Run Elixir test
         BCS C38BE3      ; Heal if passed
C38C06:  LDX $ED         ; Member index
         INX             ; Member index +1
         INX             ; Member index +1
         CPX #$0008      ; Done 4 members?
         BNE C38BFA      ; Loop if not
         BRA C38BD0      ; Make item fail

; Fork: Sleeping Bag (B)
C38C11:  LDA $0014,Y     ; Dark/Zom/Pois?
         AND #$F7        ; Clear/Imp/Pet/KO?
         BNE C38BE3      ; Succeed if any
         LDA $0015,Y     ; Status HB
         AND #$80        ; Float?
         BNE C38BE3      ; Succeed if so
         JSR C32B9A      ; At full HP?
         BCC C38BE3      ; Succeed if not
         JSR C32BBC      ; At full MP?
         BCC C38BE3      ; Succeed if not
         BRA C38BD0      ; Make item fail

; Get selected recovery item
C38C2B:  TDC             ; Clear A
         LDA $28         ; Inventory slot
         TAX             ; Index it
         LDA $1869,X     ; Item in slot
         RTS

; Handle HP and MP recovery from item
C38C33:  PHY             ; ...
         JSR C38C2B      ; Item
         JSR C38321      ; Compute index
         PLY             ; ...
         LDX $2134       ; Load it
         STX $B0         ; Memorize it
         JSR C38CCD      ; Load item power
         LDA $D85013,X   ; Fixed healing?
         BMI C38C76      ; Branch if not
         AND #$08        ; Affects HP?
         BEQ C38C5C      ; Branch if not

; Fork: Fixed HP healing
C38C4D:  REP #$21        ; 16-bit A; C-
         LDA $B2         ; Item's power
         ADC $0009,Y     ; Add target's HP
         STA $0009,Y     ; Set target's HP
         SEP #$20        ; 8-bit A
         JSR C32B9A      ; Enforce max HP

; Fork: Fixed MP healing
C38C5C:  LDX $B0         ; Item index
         LDA $D85013,X   ; Properties
         AND #$10        ; Affects MP?
         BEQ C38C75      ; Exit if not
         REP #$21        ; 16-bit A; C-
         LDA $B2         ; Item's power
         ADC $000D,Y     ; Add target's MP
         STA $000D,Y     ; Set target's MP
         SEP #$20        ; 8-bit A
         JSR C32BBC      ; Enforce max MP
C38C75:  RTS

; Fork: Fractional HP healing
C38C76:  LDA $D85013,X   ; Properties
         AND #$08        ; Affects HP?
         BEQ C38CA0      ; Branch if not
         LDA $000B,Y     ; Max HP LB
         STA $F3         ; Memorize it
         LDA $000C,Y     ; Max HP HB
         STA $F4         ; Memorize it
         JSR C30D65      ; Add gear bonus
         JSR C30D92      ; Cap at 9999
         JSR C38CD6      ; Max HP x Pwr/16
         REP #$21        ; 16-bit A; C-
         LDA $E9         ; Product
         ADC $0009,Y     ; Add target's HP
         STA $0009,Y     ; Set target's HP
         SEP #$20        ; 8-bit A
         JSR C32B9A      ; Enforce max HP

; Fork: Fractional MP healing
C38CA0:  LDX $B0         ; Item index
         LDA $D85013,X   ; Properties
         AND #$10        ; Affects MP?
         BEQ C38CCC      ; Exit if not
         LDA $000F,Y     ; Max MP LB
         STA $F3         ; Memorize it
         LDA $0010,Y     ; Max MP HB
         STA $F4         ; Memorize it
         JSR C30D65      ; Add gear bonus
         JSR C30D9F      ; Cap at 999
         JSR C38CD6      ; Max MP x Pwr/16
         REP #$21        ; 16-bit A; C-
         LDA $E9         ; Product
         ADC $000D,Y     ; Add target's MP
         STA $000D,Y     ; Set target's MP
         SEP #$20        ; 8-bit A
         JSR C32BBC      ; Enforce max MP
C38CCC:  RTS

; Load recovery item's power
C38CCD:  LDA $D85014,X   ; Item's power
         STA $B2         ; Memorize it
         STZ $B3         ; Clear HB
         RTS

; Multiply max HP or MP by item's power, divide by 16
C38CD6:  LDA $4212       ; PPU status
         AND #$40        ; H-Blank?
         BEQ C38CD6      ; Loop if not
         LDA $F3         ; Max HP/MP LB
         STA $211B       ; Set matrix A LB
         LDA $F4         ; Max HP/MP HB
         STA $211B       ; Set matrix A HB
         LDA $B2         ; Item's power
         STA $211C       ; Set matrix B
         STA $211C       ; ...
         LDA $2136       ; Product HB
         STA $EB         ; Set gain B3
         STZ $EC         ; Clear byte 4
         REP #$20        ; 16-bit A
         LDA $2134       ; Product LBs
         STA $E9         ; Set gain LBs
         LSR $EB         ; Halve HBs
         ROR $E9         ; Halve LBs w/ C
         LSR $EB         ; Halve HBs
         ROR $E9         ; Halve LBs w/ C
         LSR $EB         ; Halve HBs
         ROR $E9         ; Halve LBs w/ C
         LSR $EB         ; Halve HBs
         ROR $E9         ; Halve LBs w/ C
         SEP #$20        ; 8-bit A
         RTS

; Text pointers for Item menu
C38D10:  dw C38D1D       ; USE
         dw C38D23       ; ARRANGE
         dw C38D2D       ; RARE

; Positioned text for Item menu
C38D16:  dw $790D : db "Item",$00
C38D1D:  dw $791D : db "USE",$00
C38D23:  dw $7927 : db "ARRANGE",$00
C38D2D:  dw $7939 : db "RARE",$00

; Text for gear data menu
C38D34:  db " can be used by:",$00

; Text pointers for gear data menu
C38D45:  dw C38D77       ; Vigor
         dw C38D7F       ; Stamina
         dw C38D89       ; Mag.Pwr
         dw C38D93       ; Evade %
         dw C38D9D       ; MBlock%
         dw C38DA7       ; ..
         dw C38DAB       ; ..
         dw C38DAF       ; ..
         dw C38DB3       ; ..
         dw C38DB7       ; ..
         dw C38DBB       ; ..
         dw C38DBF       ; ..
         dw C38DC3       ; ..
         dw C38DC7       ; ..
C38D61:  dw C38DCB       ; Speed
         dw C38DD3       ; Bat.Pwr
         dw C38DDD       ; Defense
         dw C38DE7       ; Mag.Def
C38D69:  dw C38DF1       ; 50% Dmg
         dw C38DFB       ; Absorb HP
         dw C38E07       ; No Effect
         dw C38E13       ; Weak pt

; Positioned text for gear data menu
C38D71:  dw $8643 : db "???",$00
C38D77:  dw $842F : db "Vigor",$00
C38D7F:  dw $852F : db "Stamina",$00
C38D89:  dw $85AF : db "Mag.Pwr",$00
C38D93:  dw $872F : db "Evade %",$00
C38D9D:  dw $882F : db "MBlock%",$00
C38DA7:  dw $843F : db !2dot,$00
C38DAB:  dw $84BF : db !2dot,$00
C38DAF:  dw $853F : db !2dot,$00
C38DB3:  dw $85BF : db !2dot,$00
C38DB7:  dw $863F : db !2dot,$00
C38DBB:  dw $86BF : db !2dot,$00
C38DBF:  dw $873F : db !2dot,$00
C38DC3:  dw $87BF : db !2dot,$00
C38DC7:  dw $883F : db !2dot,$00
C38DCB:  dw $84AF : db "Speed",$00
C38DD3:  dw $862F : db "Bat.Pwr",$00
C38DDD:  dw $86AF : db "Defense",$00
C38DE7:  dw $87AF : db "Mag.Def",$00
C38DF1:  dw $7B8D : db "50% Dmg",$00
C38DFB:  dw $7BA9 : db "Absorb HP",$00
C38E07:  dw $7C8D : db "No Effect",$00
C38E13:  dw $7CA9 : db "Weak pt",$00
C38E1D:  dw $7B8D : db "Attack",$00
C38E26:  dw $822F : db "SwdTech",$00
C38E30:  dw $82AF : db "Runic",$00
C38E38:  dw $832F : db "2-hand",$00

; Positioned text for item usage menu
C38E41:  dw $7A0D : db "Owned:",$00

; Positioned spaces for blanking item count in Item menu
C38E4A:  dw $7ABF : db "   ",$00

; Load navigation data for Equip menu options
C38E50:  LDY #C38E5F     ; C3/8E5F
         JMP C305FE      ; Load navig data

; Handle D-Pad for Equip menu options
C38E56:  JSR C3072D      ; Handle D-Pad
C38E59:  LDY #C38E64     ; C3/8E64
         JMP C30640      ; Relocate cursor

; Navigation data for Equip menu options
C38E5F:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $04          ; 4 columns
         db $01          ; 1 row

; Cursor positions for Equip menu options
C38E64:  dw $1000        ; EQUIP
         dw $1038        ; OPTIMUM
         dw $1080        ; RMOVE
         dw $10B8        ; EMPTY

; Load navigation data for Equip menu slot selection
C38E6C:  LDY #C38E7B     ; C3/8E7B
         JMP C305FE      ; Load navig data

; Handle D-Pad for Equip menu slot selection
C38E72:  JSR C3072D      ; Handle D-Pad
C38E75:  LDY #C38E80     ; C3/8E80
         JMP C30640      ; Relocate cursor

; Navigation data for Equip menu slot selection
C38E7B:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $04          ; 4 rows

; Cursor positions for Equip menu slot selection
C38E80:  dw $2C00        ; R-Hand
         dw $3800        ; L-Hand
         dw $4400        ; Head
         dw $5000        ; Body

; Load navigation data for equipment browsing
C38E88:  LDY #C38EA6     ; C3/8EA6
         JMP C305FE      ; Load navig data

; Handle D-Pad for equipment browsing (over 9 items)
C38E8E:  JSR C381C7      ; Handle D-Pad
C38E91:  LDY #C38EAB     ; C3/8EAB
         JMP C30648      ; Relocate cursor

; Load navigation data for equipment browsing
C38E97:  LDY #C38EA6     ; C3/8EA6
         JMP C305FE      ; Load navig data

; Handle D-Pad for equipment browsing (9 items or less)
C38E9D:  JSR C3072D      ; Handle D-Pad
C38EA0:  LDY #C38EAB     ; C3/8EAB
         JMP C30640      ; Relocate cursor

; Navigation data for equipment list
C38EA6:  db $81          ; Never wraps
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $09          ; 9 rows

; Cursor positions for equipment list
C38EAB:  dw $6800        ; Item 1
         dw $7400        ; Item 2
         dw $8000        ; Item 3
         dw $8C00        ; Item 4
         dw $9800        ; Item 5
         dw $A400        ; Item 6
         dw $B000        ; Item 7
         dw $BC00        ; Item 8
         dw $C800        ; Item 9

; Load navigation data for Relic menu options
C38EBD:  LDY #C38ECC     ; C3/8ECC
         JMP C305FE      ; Load navig data

; Handle D-Pad for Relic menu options
C38EC3:  JSR C3072D      ; Handle D-Pad
C38EC6:  LDY #C38ED1     ; C3/8ED1
         JMP C30640      ; Relocate cursor

; Navigation data for Relic menu options
C38ECC:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $02          ; 2 columns
         db $01          ; 1 row

; Cursor positions for Relic menu options
C38ED1:  dw $1010        ; Equip
         dw $1048        ; Remove

; Load navigation data for relic slot selection
C38ED5:  LDY #C38EE4     ; C3/8EE4
         JMP C305FE      ; Load navig data

; Handle D-Pad for relic slot selection
C38EDB:  JSR C3072D      ; Handle D-Pad
C38EDE:  LDY #C38EE9     ; C3/8EE9
         JMP C30640      ; Relocate cursor

; Navigation data for relic slot selection
C38EE4:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $02          ; 2 rows

; Cursor positions for relic slots
C38EE9:  dw $4400        ; Relic 1
         dw $5000        ; Relic 2

; Draw party gear overview
C38EED:  LDA #$02        ; 32x64 at $0000
         STA $2107       ; Set BG1 map loc
         JSR C36A28      ; Clear BG2 map A
         LDY #C3902E     ; C3/902E
         JSR C30341      ; Draw window
         JSR C30E52      ; Upload window
         JSR C36A15      ; Clear BG1 map A
         JSR C36A19      ; Clear BG1 map B
         JSR C38F1C      ; Handle member 1
         JSR C38F36      ; Handle member 2
         JSR C38F52      ; Handle member 3
         JSR C38F6E      ; Handle member 4
         JSR C30E28      ; Upload BG1 A+B
         JSR C30E36      ; Upload BG1 C...
         JSR C36A3C      ; Clear BG3 map A
         JMP C30E6E      ; Upload BG3 A+B

; Draw text in party gear overview for member 1
C38F1C:  LDA $69         ; Nobody here?
         BMI C38F35      ; Exit if so
         LDX $6D         ; Actor's address
         STX $67         ; Memorize it
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDY #$390D      ; Text position
         JSR C334CF      ; Draw actor name
         STZ $28         ; Member slot: 1
         LDA #$04        ; Base Y: 4
         JSR C38F8A      ; Draw equipment
C38F35:  RTS

; Draw text in party gear overview for member 2
C38F36:  LDA $6A         ; Nobody here?
         BMI C38F51      ; Exit if so
         LDX $6F         ; Actor's address
         STX $67         ; Memorize it
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDY #$3B0D      ; Text position
         JSR C334CF      ; Draw actor name
         LDA #$01        ; Member: 2
         STA $28         ; Set member slot
         LDA #$0C        ; Base Y: 12
         JSR C38F8A      ; Draw equipment
C38F51:  RTS

; Draw text in party gear overview for member 3
C38F52:  LDA $6B         ; Nobody here?
         BMI C38F6D      ; Exit if so
         LDX $71         ; Actor's address
         STX $67         ; Memorize it
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDY #$3D0D      ; Text position
         JSR C334CF      ; Draw actor name
         LDA #$02        ; Member: 3
         STA $28         ; Set member slot
         LDA #$14        ; Base Y: 20
         JSR C38F8A      ; Draw equipment
C38F6D:  RTS

; Draw text in party gear overview for member 4
C38F6E:  LDA $6C         ; Nobody here?
         BMI C38F89      ; Exit if so
         LDX $73         ; Actor's address
         STX $67         ; Memorize it
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDY #$3F0D      ; Text position
         JSR C334CF      ; Draw actor name
         LDA #$03        ; Member: 4
         STA $28         ; Set member slot
         LDA #$1C        ; Base Y: 28
         JSR C38F8A      ; Draw equipment
C38F89:  RTS

; Draw member's gear in party gear overview
C38F8A:  STA $E2         ; Set base Y
         STZ $E0         ; ...
         LDY $67         ; Actor's address
         TDC             ; Clear A
         TAX             ; 1st: R-Hand
C38F92:  PHX             ; Push gear slot
         PHY             ; Push actor adr
         PHY             ; Push actor adr
         PHX             ; Push gear slot
         STZ $E5         ; X-Pos HB: 0
         LDA.L C38FD5,X  ; X position
         STA $E4         ; Memorize it
         LDA.L C38FDB,X  ; Relative Y
         CLC             ; Prepare ADC
         ADC $E2         ; Add base Y
         LDX $E4         ; X position
         JSR C3809F      ; Compute map ptr
         REP #$20        ; 16-bit A
         TXA             ; ...
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         PLX             ; Gear slot
         CPX #$0002      ; Either hand?
         BCS C38FBE      ; Branch if not
         JSR C3941D      ; Test "Empty"
         BRA C38FC0      ; Skip a line
C38FBE:  STZ $E0         ; Forbid "Empty"
C38FC0:  PLY             ; Actor's address
         TDC             ; ...
         LDA $001F,Y     ; Item in slot
         JSR C38FE1      ; Load name
         JSR C37FD9      ; Draw name
         PLY             ; Actor's address
         INY             ; Reach next slot
         PLX             ; Gear slot
         INX             ; Point to next
         CPX #$0006      ; Done 6 slots?
         BNE C38F92      ; Loop if not
         RTS

; X positions for party gear overview
C38FD5:  db $02          ; R-Hand
         db $11          ; L-Hand
         db $02          ; Head
         db $11          ; Body
         db $02          ; Relic 1
         db $11          ; Relic 2

; Relative Y positions for party gear overview
C38FDB:  db $01          ; R-Hand
         db $01          ; L-Hand
         db $03          ; Head
         db $03          ; Body
         db $05          ; Relic 1
         db $05          ; Relic 2

; Load equipped item's name
C38FE1:  PHA             ; Save item
         LDX #$9E8B      ; 7E/9E8B
         STX $2181       ; Set WRAM LBs
C38FE8:  LDA $4212       ; PPU status
         AND #$40        ; H-Blank?
         BEQ C38FE8      ; Loop if not
         TDC             ; Clear A
         LDA $E0         ; Allow "Empty"?
         BEQ C38FF7      ; Branch if not
         PLA             ; Item
         BRA C38FFC      ; Skip next check
C38FF7:  PLA             ; Item
         CMP #$FF        ; None?
         BEQ C3901F      ; Blank if so
C38FFC:  STA $211B       ; Set matrix A LB
         STZ $211B       ; Clear HB
         LDA #$0D        ; Name data size
         STA $211C       ; Set matrix B
         STA $211C       ; ...
         LDX $2134       ; Index product
         LDY #$000D      ; Letters: 13
C39010:  LDA $D2B300,X   ; Letter
         STA $2180       ; Add to string
         INX             ; Point to next
         DEY             ; One less left
         BNE C39010      ; Loop till last
         STZ $2180       ; End string
         RTS

; Fork: Blank item name
C3901F:  LDY #$000D      ; Spaces: 13
         LDA #$FF        ; Space char
C39024:  STA $2180       ; Add to string
         DEY             ; One less left
         BNE C39024      ; Loop till last
         STZ $2180       ; End string
         RTS

; Window layout for party gear overview
C3902E:  dw $588B,$181C  ; 30x26 at $588B

; Draw Equip menu, create portrait, update status via gear
C39032:  JSR C39093      ; Do boxes; face
         JSR C3911B      ; Draw info; status
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         LDX #C3A2AE     ; Text ptrs loc
         LDY #$0004      ; Strings: 2
         JSR C369BA      ; Draw Head, Body
         JSR C3904E      ; Draw top options
         JSR C30E6E      ; Upload BG3 A+B
         JMP C39E0F      ; Queue text upload

; Draw options in Equip menu
C3904E:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDX #C3A2A6     ; Text ptrs loc
         LDY #$0008      ; Strings: 4
         JSR C369BA      ; Draw text
         RTS

; Draw options in Relic menu
C3905C:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDX #C3A2B2     ; Text ptrs loc
         LDY #$0004      ; Strings: 2
         JSR C369BA      ; Draw text
         RTS

; Draw Relic menu, memorize original relics, create portrait
C3906A:  JSR C39093      ; Do boxes; face
         JSR C393F2      ; Define Y
         LDA $0023,Y     ; Relic 1
         STA $B0         ; Save for Reequip
         LDA $0024,Y     ; Relic 2
         STA $B1         ; Save for Reequip
         JSR C39131      ; Draw info; status
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         LDX #C3A2B6     ; Text ptrs loc
         LDY #$0004      ; Strings: 2
         JSR C369BA      ; Draw 2x "Relic"
         JSR C3905C      ; Draw menu options
         JSR C3A6AB      ; Build desc map
         JMP C30E6E      ; Upload BG3 A+B

; Draw elements shared by Equip and Relic menus, create portrait
C39093:  JSR C39110      ; Load actor stats
         REP #$20        ; 16-bit A
         LDA #$0100      ; BG1 H-Shift: 256
         STA $7E9BD0     ; Hide gear list
         SEP #$20        ; 8-bit A
         LDA #$01        ; 64x32 at $0000
         STA $2107       ; Set BG1 map loc
         LDA #$42        ; 32x64 at $4000
         STA $2109       ; Set BG3 map loc
         JSR C3960C      ; Reset BG2 X-Pos
         JSR C36A28      ; Clear BG2 map A
         JSR C36A2D      ; Clear BG2 map B
         LDY #C3947F     ; C3/947F
         JSR C30341      ; Draw stats box A
         LDY #C39483     ; C3/9483
         JSR C30341      ; Draw gear box A
         LDY #C39487     ; C3/9487
         JSR C30341      ; Draw option box
         LDY #C3948B     ; C3/948B
         JSR C30341      ; Draw stats box B
         LDY #C3948F     ; C3/948F
         JSR C30341      ; Draw gear box B
         LDY #C39493     ; C3/9493
         JSR C30341      ; Draw title box
         JSR C30E52      ; Upload windows
         JSR C36A15      ; Clear BG1 map A
         JSR C36A19      ; Clear BG1 map B
         JSR C30E28      ; Upload BG1 A+B
         JSR C30E36      ; Upload BG1 C...
         JSR C36A3C      ; Clear BG3 map A
         JSR C36A41      ; Clear BG3 map B
         JSR C393E5      ; Draw actor name
         JSR C361B2      ; Create portrait
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         LDX #C3A34D     ; Text ptrs loc
         LDY #$001C      ; Strings: 14
         JSR C369BA      ; Draw Vigor, etc.
         LDA #$2C        ; ...
         STA $29         ; ...
         LDX #C3A369     ; Text ptrs loc
         LDY #$0008      ; Strings: 4
         JSR C369BA      ; Draw Speed, etc.
         JMP C30E6E      ; Upload BG3 A+B

; Load member's stats and properties with gear
C39110:  TDC             ; Clear A
         LDA $28         ; Member slot
         TAX             ; Index it
         LDA $69,X       ; Actor
         JSL $C20006     ; Load data
         RTS

; Draw actor info in Equip menu, update status based on gear
C3911B:  JSR C39975      ; Draw hand names
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         JSR C3913E      ; Do stats; status
         JSR C3922D      ; SFC: Relic FX...
         JSR C393FC      ; Draw arms
         JSR C39435      ; Draw helmet
         JMP C39443      ; Draw armor

; Draw actor info in Relic menu, update status based on gear
C39131:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         JSR C3913E      ; Do stats; status
         JSR C39451      ; Draw relic 1
         JMP C3945F      ; Draw relic 2

; Draw current stats in gear menu, update status based on gear
C3913E:  JSR C39110      ; Load actor stats
         JSR C393F2      ; Actor's address
         JSR C399E8      ; Set Bat.Pwr mode
         JSR C39207      ; Relocate stats
         PHB             ; Save DB
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         JSR C391C4      ; Update status
         LDA $3006       ; Vigor
         JSR C304E0      ; Turn into text
         LDX #$7CB7      ; Text position
         JSR C304C0      ; Draw 3 digits
         LDA $3004       ; Speed
         JSR C304E0      ; Turn into text
         LDX #$7D37      ; Text position
         JSR C304C0      ; Draw 3 digits
         LDA $3002       ; Stamina
         JSR C304E0      ; Turn into text
         LDX #$7DB7      ; Text position
         JSR C304C0      ; Draw 3 digits
         LDA $3000       ; Mag.Pwr
         JSR C304E0      ; Turn into text
         LDX #$7E37      ; Text position
         JSR C304C0      ; Draw 3 digits
         JSR C393AB      ; Define Bat.Pwr
         LDX $F1         ; Load it
         STX $F3         ; Save for $052E
         JSR C3052E      ; Turn into text
         LDX #$7EB7      ; Text position
         JSR C30486      ; Draw 3 digits
         LDA $301A       ; Defense
         JSR C304E0      ; Turn into text
         LDX #$7F37      ; Text position
         JSR C304C0      ; Draw 3 digits
         LDA $3008       ; Evade
         JSR C304E0      ; Turn into text
         LDX #$7FB7      ; Text position
         JSR C304C0      ; Draw 3 digits
         LDA $301B       ; Mag.Def
         JSR C304E0      ; Turn into text
         LDX #$8037      ; Text position
         JSR C304C0      ; Draw 3 digits
         LDA $300A       ; MBlock
         JSR C304E0      ; Turn into text
         LDX #$80B7      ; Text position
         JSR C304C0      ; Draw 3 digits
         PLB             ; Restore DB
         RTS

; Update status based on gear (Rage denotes Auto Float)
C391C4:  JSR C393F2      ; Define Y
         LDA $7E3032     ; Gear immunity
         JSR C391EC      ; Deny ailments
         LDA $3034       ; Gear auto status
         AND #$01        ; Float?
         BNE C391DC      ; Branch if so
         LDA $0015,Y     ; Actor's status
         AND #$01        ; Rage?
         BEQ C391EB      ; Exit if not
C391DC:  LDA $3034       ; Gear auto status
         CLC             ; Prepare ROR
         AND #$01        ; Get Float
         STA $E0         ; Memorize it
         ROR A           ; Put in Carry
         ROR A           ; Put in bit 7
         ORA $E0         ; Add Float as Rage
         STA $0015,Y     ; Set actor status
C391EB:  RTS

; Cure ailments blocked by gear
C391EC:  AND #$25        ; Dark, Poison, Imp
         EOR #$FF        ; Toggle all bits
         STA $E1         ; Save immunities
         LDA $0014,Y     ; Actor's status
         AND $E1         ; Lift immune ones
         STA $0014,Y     ; Save changes
         RTS

; Grant Float status if bestowed by gear
C391FB:  CLC             ; Prepare ROR
         AND #$01        ; Auto Float
         ROR A           ; Put in Carry
         ROR A           ; Put in bit 7
         ORA $0015,Y     ; Add status
         STA $0015,Y     ; Set status
         RTS

; Load actor's info for Equip or Relic menu
C39207:  LDX $00         ; 1st: Mag.Pwr
         REP #$20        ; 16-bit A
C3920B:  LDA $11A0,X     ; Actor info
         STA $7E3000,X   ; Set as current
         INX             ; Index +1
         INX             ; Index +1
         LDA $11A0,X     ; Actor info
         STA $7E3000,X   ; Set as current
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0040      ; Done 64 bytes?
         BNE C3920B      ; Loop if not
         SEP #$20        ; 8-bit A
         LDA $A1         ; 2-hand flag
         STA $A0         ; Set as current
         LDA $CD         ; Genji G. flag
         STA $CE         ; Set as current
         RTS             ; ...
C3922D:  RTS

; Set text color to blue (SFC)
C3922E:  LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         RTS

; Draw projected stats in Equip or Relic menu
C39233:  LDA $7E9D89     ; Empty item list?
         BEQ C3923E      ; Abort if so
         JSR C39A42      ; On a gray item?
         BCS C39241      ; Branch if not
C3923E:  JMP C39C87      ; Clear stats
C39241:  JSR C393F2      ; Actor's address
         LDA $25         ; Submenu
         CMP #$02        ; Equip menu?
         BEQ C3924E      ; Branch if so
         INY             ; Point to L-Hand
         INY             ; Point to head
         INY             ; Point to body
         INY             ; Point to relic 1
C3924E:  REP #$21        ; 16-bit A; C-
         TYA             ; Actor's address
         SEP #$20        ; 8-bit A
         ADC $5F         ; Add body slot
         TAY             ; Index sum
         TDC             ; Clear A
         LDA $4B         ; Gear list slot
         TAX             ; Index it
         LDA $7E9D8A,X   ; Inventory slot
         TAX             ; Index it
         LDA $001F,Y     ; Equipped item
         STA $64         ; Preserve it
         LDA $1869,X     ; Inventory item
         STA $001F,Y     ; Put on actor
         PHY             ; Save actor adr
         JSR C39110      ; Load actor data
         JSR C393F2      ; Base actor adr
         JSR C399E8      ; Set Bat.Pwr mode
         JSR C39320      ; Set stat colors
         LDA $11A6       ; New Vigor
         JSR C304E0      ; Turn into text
         LDX #$7CBF      ; Text position
         LDA $7E3040     ; Vigor palette
         STA $29         ; Set as current
         JSR C304C0      ; Draw 3 digits
         LDA $11A4       ; New Speed
         JSR C304E0      ; Turn into text
         LDX #$7D3F      ; Text position
         LDA $7E3041     ; Speed palette
         STA $29         ; Set as current
         JSR C304C0      ; Draw 3 digits
         LDA $11A2       ; New Stamina
         JSR C304E0      ; Turn into text
         LDX #$7DBF      ; Text position
         LDA $7E3042     ; Stamina palette
         STA $29         ; Set as current
         JSR C304C0      ; Draw 3 digits
         LDA $11A0       ; New Mag.Pwr
         JSR C304E0      ; Turn into text
         LDX #$7E3F      ; Text position
         LDA $7E3043     ; Mag.Pwr palette
         STA $29         ; Set as current
         JSR C304C0      ; Draw 3 digits
         JSR C39371      ; Define Bat.Pwr
         JSR C3052E      ; Turn into text
         LDX #$7EBF      ; Text position
         LDA $7E3048     ; Bat.Pwr palette
         STA $29         ; Set as current
         JSR C30486      ; Draw 3 digits
         LDA $11BA       ; New Defense
         JSR C304E0      ; Turn into text
         LDX #$7F3F      ; Text position
         LDA $7E3044     ; Defense palette
         STA $29         ; Set as current
         JSR C304C0      ; Draw 3 digits
         LDA $11A8       ; New Evade
         JSR C304E0      ; Turn into text
         LDX #$7FBF      ; Text position
         LDA $7E3045     ; Evade palette
         STA $29         ; Set as current
         JSR C304C0      ; Draw 3 digits
         LDA $11BB       ; New Mag.Def
         JSR C304E0      ; Turn into text
         LDX #$803F      ; Text position
         LDA $7E3046     ; Mag.Def palette
         STA $29         ; Set as current
         JSR C304C0      ; Draw 3 digits
         LDA $11AA       ; New MBlock
         JSR C304E0      ; Turn into text
         LDX #$80BF      ; Text position
         LDA $7E3047     ; MBlock palette
         STA $29         ; Set as current
         JSR C304C0      ; Draw 3 digits
         PLY             ; Actor address
         LDA $64         ; Original item
         STA $001F,Y     ; Restore gear
         RTS

; Set color for each projected stat in Equip or Relic menu
C39320:  PHB             ; Save DB
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         TDC             ; Clear A
         TAX             ; Stat index: 0
C39327:  LDA.L C39369,X  ; Stat pointer
         PHX             ; Save index
         TAX             ; Index pointer
         LDA $0011A0,X   ; Projected stat
         CMP $3000,X     ; Matches old?
         BEQ C3933C      ; Branch if so
         BCC C39340      ; Gray if less
         LDA #$28        ; Palette 2
         BRA C39342      ; Color: Yellow

; Fork: Use player's color
C3933C:  LDA #$20        ; Palette 0
         BRA C39342      ; Skip a line

; Fork: Gray out statistic
C39340:  LDA #$24        ; Palette 1
C39342:  PLX             ; Stat index
         STA $3040,X     ; Set stat color
         INX             ; Stat index +1
         CPX #$0008      ; Done 8 stats?
         BNE C39327      ; Loop if not

; Fork: Handle Bat.Pwr
C3934C:  JSR C39371      ; Set new Bat.Pwr
         JSR C393AB      ; Set old Bat.Pwr
         LDY $F3         ; New Bat.Pwr
         CPY $F1         ; Matches old?
         BEQ C3935E      ; Branch if so
         BCC C39362      ; Gray if less
         LDA #$28        ; Palette 2
         BRA C39364      ; Font: Yellow

; Fork: Use player's color for Bat.Pwr
C3935E:  LDA #$20        ; Palette 0
         BRA C39364      ; Skip a line

; Fork: Gray out Bat.Pwr
C39362:  LDA #$24        ; Palette 1
C39364:  STA $3048       ; Set BP color
         PLB             ; Restore DB
         RTS

; Ordered index list for loading stats
C39369:  db $06          ; Vigor
         db $04          ; Speed
         db $02          ; Stamina
         db $00          ; Mag.Pwr
         db $1A          ; Defense
         db $08          ; Evade
         db $1B          ; Mag.Def
         db $0A          ; MBlock

; Define current (Status) or projected (Equip, Relic) Bat.Pwr
C39371:  LDA $A1         ; 2-hand mode?
         BEQ C3938B      ; Branch if not
         LDA $0011AC     ; R-Hand's power
         BEQ C39381      ; Branch if 0
         STA $0011AD     ; Set as L-Hand's
         BRA C3939A      ; Combine hands

; Fork: Two-handing L-Hand weapon
C39381:  LDA $0011AD     ; L-Hand's power
         STA $0011AC     ; Set as R-Hand's
         BRA C3939A      ; Combine hands

; Fork: Not two-handing a weapon
C3938B:  LDA $CD         ; Got Genji Glove?
         BNE C3939A      ; Branch if so
         LDA $0011AC     ; R-Hand's power
         BEQ C3939A      ; Branch if 0
         TDC             ; Bat.Pwr: 0
         STA $0011AD     ; Set L-Hand's

; Fork: Combine hands' Bat.Pwr
C3939A:  LDA $0011AC     ; R-Hand's power
         CLC             ; Prepare ADC
         ADC $0011AD     ; Add L-Hand's
         STA $F3         ; Set Bat.Pwr LB
         TDC             ; Zero A
         ADC #$00        ; +1 if overflow
         STA $F4         ; Set Bat.Pwr HB
         RTS

; Define current Bat.Pwr for Equip or Relic menu
C393AB:  LDA $A0         ; 2-hand mode?
         BEQ C393C5      ; Branch if not
         LDA $7E300C     ; R-Hand's power
         BEQ C393BB      ; Branch if 0
         STA $7E300D     ; Set as L-Hand's
         BRA C393D4      ; Combine hands

; Fork: Two-handing L-Hand weapon
C393BB:  LDA $7E300D     ; L-Hand's power
         STA $7E300C     ; Set as R-Hand's
         BRA C393D4      ; Combine hands

; Fork: Not two-handing a weapon
C393C5:  LDA $CE         ; Got Genji Glove?
         BNE C393D4      ; Branch if so
         LDA $7E300C     ; R-Hand's power
         BEQ C393D4      ; Branch if 0
         TDC             ; Bat.Pwr: 0
         STA $7E300D     ; Set L-Hand's

; Fork: Combine hands' Bat.Pwr
C393D4:  LDA $7E300C     ; R-Hand's power
         CLC             ; Prepare ADC
         ADC $7E300D     ; Add L-Hand's
         STA $F1         ; Set Bat.Pwr LB
         TDC             ; Zero A
         ADC #$00        ; +1 if overflow
         STA $F2         ; Set Bat.Pwr HB
         RTS

; Draw actor name in Equip or Relic menu
C393E5:  JSR C393F2      ; Actor's address
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDY #$7BB7      ; Text position
         JMP C334CF      ; Draw actor name

; Load member's SRAM block address
C393F2:  TDC             ; Clear A
         LDA $28         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         LDY $6D,X       ; Address
         STY $67         ; Memorize it
         RTS

; Draw equipped armaments in Equip menu
C393FC:  JSR C3941D      ; Test Empty x2
         LDX #$7A1B      ; Tilemap ptr
         JSR C3946D      ; Set Y, coords
         LDA $001F,Y     ; R-Hand item
         JSR C38FE1      ; Load name
         JSR C37FD9      ; Draw name
         JSR C3941D      ; Test Empty x2
         LDX #$7A9B      ; Tilemap ptr
         JSR C3946D      ; Set Y, coords
         LDA $0020,Y     ; L-Hand item
         JMP C39479      ; Draw name

; Check if "Empty" should be drawn for both hands
C3941D:  JSR C393F2      ; Define Y
         LDA $001F,Y     ; R-Hand item
         CMP #$FF        ; Nothing?
         BNE C39432      ; Forbid if not
         LDA $0020,Y     ; L-Hand item
         CMP #$FF        ; Nothing?
         BNE C39432      ; Forbid if not
         STA $E0         ; Allow "Empty"
         BRA C39434      ; Exit
C39432:  STZ $E0         ; Forbid "Empty"
C39434:  RTS

; Draw equipped helmet in Equip menu
C39435:  LDX #$7B1B      ; Tilemap ptr
         JSR C3946D      ; Set Y, coords
         STZ $E0         ; Forbid "Empty"
         LDA $0021,Y     ; Helmet
         JMP C39479      ; Draw its name

; Draw equipped armor in Equip menu
C39443:  LDX #$7B9B      ; Tilemap ptr
         JSR C3946D      ; Set Y, coords
         STZ $E0         ; Forbid "Empty"
         LDA $0022,Y     ; Armor
         JMP C39479      ; Draw its name

; Draw equipped relic 1 in Relic menu
C39451:  LDX #$7B1B      ; Tilemap ptr
         JSR C3946D      ; Set Y, coords
         STZ $E0         ; Forbid "Empty"
         LDA $0023,Y     ; Relic 1
         JMP C39479      ; Draw its name

; Draw equipped relic 2 in Relic menu
C3945F:  LDX #$7B9B      ; Tilemap ptr
         JSR C3946D      ; Set Y, coords
         STZ $E0         ; Forbid "Empty"
         LDA $0024,Y     ; Relic 2
         JMP C39479      ; Draw its name

; Set text position and load actor data address
C3946D:  REP #$20        ; 16-bit A
         TXA             ; Tilemap ptr
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         JMP C393F2      ; Load address

; Load and draw equipped item's name
C39479:  JSR C38FE1      ; Load item name
         JMP C37FD9      ; Draw item name

; Window layout for Equip and Relic menus
C3947F:  dw $5B4B,$0D1C  ; 30x15 at $5B4B (Stats w/o title)
C39483:  dw $590B,$071C  ; 30x09 at $590B (Gear w/o title)
C39487:  dw $588B,$021C  ; 30x04 at $588B (Options)
C3948B:  dw $634B,$0D1C  ; 30x15 at $634B (Stats w/ title)
C3948F:  dw $610B,$071C  ; 30x09 at $610B (Gear w/ title)
C39493:  dw $60B7,$0206  ; 08x04 at $60B7 (Title)

; Set to condense text for party gear overview or final battle lineup
C39497:  LDA #$02        ; 1Rx2B to PPU
         STA $4350       ; Set DMA mode
         LDA #$0E        ; $210E
         STA $4351       ; To BG1 V-Scroll
         LDY #C395D8     ; C3/95D8
         STY $4352       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4354       ; Set src HB
         LDA #$C3        ; ...
         STA $4357       ; Set indir HB
         LDA #$20        ; Channel: 5
         TSB $43         ; Queue HDMA-5
         RTS

; Set to condense text in Equip or Relic menu
C394B6:  LDA #$02        ; 1Rx2B to PPU
         STA $4350       ; Set CH5 mode
         LDA #$12        ; $2112
         STA $4351       ; To BG3 V-Scroll
         LDY #C395D8     ; C3/95D8
         STY $4352       ; Set CH5 src LBs
         LDA #$C3        ; Bank: C3
         STA $4354       ; Set CH5 src HB
         LDA #$C3        ; ...
         STA $4357       ; Set indir HB
         LDA #$20        ; Channel: 5
         TSB $43         ; Queue HDMA-5
         JSR C39520      ; Load BG1 V-Data
         LDX $00         ; Index: 0
C394D9:  LDA.L C39564,X  ; BG1 H-Pan data
         STA $7E9BC9,X   ; Save in RAM
         INX             ; Index +1
         CPX #$000D      ; End of table?
         BNE C394D9      ; Loop if not
         LDA #$02        ; 1Rx2B to PPU
         STA $4360       ; Set CH6 mode
         LDA #$0D        ; $210D
         STA $4361       ; To BG1 H-Scroll
         LDY #$9BC9      ; 7E/9BC9
         STY $4362       ; Set CH6 src LBs
         LDA #$7E        ; Bank: 7E
         STA $4364       ; Set CH6 src HB
         LDA #$7E        ; ...
         STA $4367       ; Set indir HB
         LDA #$02        ; 1Rx2B to PPU
         STA $4370       ; Set CH7 mode
         LDA #$0E        ; $210E
         STA $4371       ; To BG1 V-Scroll
         LDY #$9849      ; 7E/9849
         STY $4372       ; Set CH7 src LBs
         LDA #$7E        ; Bank: 7E
         STA $4374       ; Set CH7 src HB
         LDA #$7E        ; ...
         STA $4377       ; Set indir HB
         LDA #$C0        ; Channels: 6, 7
         TSB $43         ; Queue HDMA 6+7
         RTS

; Load BG1 vertical shift table for Equip or Relic menu
C39520:  LDX $00         ; Index: 0
C39522:  LDA.L C39571,X  ; Void's V-Data
         STA $7E9849,X   ; Save in RAM
         INX             ; Index +1
         CPX #$0012      ; At item data?
         BNE C39522      ; Loop if not
C39530:  LDA.L C39571,X  ; Scanline data
         STA $7E9849,X   ; Save in RAM
         INX             ; Index +1
         TDC             ; Clear A
         LDA $49         ; BG1 top row
         ASL A           ; x2
         ASL A           ; x4
         ASL A           ; x8
         ASL A           ; x16
         AND #$FF        ; ...
         REP #$21        ; 16-bit A; C-
         ADC.L C39571,X  ; Add V-Pan data
         STA $7E9849,X   ; Save in RAM
         SEP #$20        ; 8-bit A
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0063      ; Beyond list?
         BNE C39530      ; Loop if not
C39555:  LDA.L C39571,X  ; Void's V-Data
         STA $7E9849,X   ; Save in RAM
         INX             ; Index +1
         CPX #$0067      ; End of table?
         BNE C39555      ; Loop if not
         RTS

; BG1 H-Shift table for gear list browsing
C39564:  db $27,$00,$01  ; Nothing?
         db $3C,$00,$01  ; Nothing?
         db $6C,$00,$00  ; Item list
         db $1E,$00,$01  ; Nothing?
         db $00          ; End

; BG1 V-Shift table for gear list browsing
C39571:  db $3F,$00,$00  ; Nothing?
         db $0C,$04,$00  ; Nothing?
         db $0C,$08,$00  ; Nothing?
         db $0A,$0C,$00  ; Nothing?
         db $01,$0C,$00  ; Nothing?
         db $01,$0C,$00  ; Nothing?
         db $04,$A0,$FF  ; Item row 1
         db $04,$A0,$FF  ; Item row 2
         db $04,$A0,$FF  ; Item row 3
         db $04,$A4,$FF  ; Item row 4
         db $04,$A4,$FF  ; Item row 5
         db $04,$A4,$FF  ; Item row 6
         db $04,$A8,$FF  ; Item row 7
         db $04,$A8,$FF  ; Item row 8
         db $04,$A8,$FF  ; Item row 9
         db $04,$AC,$FF  ; Item row 10
         db $04,$AC,$FF  ; Item row 11
         db $04,$AC,$FF  ; Item row 12
         db $04,$B0,$FF  ; Item row 13
         db $04,$B0,$FF  ; Item row 14
         db $04,$B0,$FF  ; Item row 15
         db $04,$B4,$FF  ; Item row 16
         db $04,$B4,$FF  ; Item row 17
         db $04,$B4,$FF  ; Item row 18
         db $04,$B8,$FF  ; Item row 19
         db $04,$B8,$FF  ; Item row 20
         db $04,$B8,$FF  ; Item row 21
         db $04,$BC,$FF  ; Item row 22
         db $04,$BC,$FF  ; Item row 23
         db $04,$BC,$FF  ; Item row 24
         db $04,$C0,$FF  ; Item row 25
         db $04,$C0,$FF  ; Item row 26
         db $04,$C0,$FF  ; Item row 27
         db $1E,$10,$00  ; Nothing?
         db $00          ; End

; V-Shift table for gear menus and final battle lineup
C395D8:  db $0F,$00,$00  ; Nothing
         db $0C,$04,$00  ; Options, title
         db $0C,$08,$00  ; Reequip mode
         db $0C,$0C,$00  ; R-Hand
         db $0C,$10,$00  ; L-Hand
         db $0C,$14,$00  ; Head, Relic 1
         db $0C,$18,$00  ; Body, Relic 2
         db $0C,$1C,$00  ; Member 2's armor
         db $0C,$20,$00  ; Vigor
         db $0C,$24,$00  ; Speed
         db $0C,$28,$00  ; Stamina
         db $0C,$2C,$00  ; Mag.Pwr
         db $0C,$30,$00  ; Bat.Pwr
         db $0C,$34,$00  ; Defense
         db $0C,$38,$00  ; Evade
         db $0C,$3C,$00  ; Mag.Def
         db $0C,$40,$00  ; MBlock
         db $00          ; End

; Switch to layout with options in Equip or Relic menu
C3960C:  JSR C3965D      ; Erase title
         LDY $00         ; X: 0
         STY $39         ; Set BG2 X-Pos
         RTS

; Switch to layout without options in Equip or Relic menu
C39614:  JSR C3965D      ; Erase options
         LDY #$0100      ; X: 256
         STY $39         ; Set BG2 X-Pos
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         RTS             ; ^ For "Equip"

; 36: Handle Equip menu options
C39621:  JSR C3960C      ; Switch windows
         JSR C3904E      ; Draw options
         JSR C38E56      ; Handle D-Pad
         LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C39635      ; Branch if not
         JSR C30EB2      ; Sound: Click
         BRA C39664      ; Handle selection

; Fork: Handle B
C39635:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C39648      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         JSR C39110      ; Update field FX
         LDA #$04        ; C3/1A8A
         STA $27         ; Queue main menu
         STZ $26         ; Next: Fade-out
         RTS

; Fork: Handle L and R, prepare for menu reset
C39648:  LDA #$35        ; C3/1BB8
         STA $E0         ; Set init command
         JMP C32022      ; Handle L and R

; Draw blue "Equip" in Equip or Relic menu
C3964F:  LDY #C3A309     ; Text pointer
         JSR C302F9      ; Draw title
         RTS

; Draw blue "Remove" in Equip or Relic menu
C39656:  LDY #C3A311     ; Text pointer
         JSR C302F9      ; Draw title
         RTS

; Erase options and title in Equip or Relic menu
C3965D:  LDY #C3A2EA     ; Text pointer
         JSR C302F9      ; Draw 28 spaces
         RTS

; Handle selected option in Equip menu
C39664:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C3966C,X)  ; Handle option

; Jump table for the above
C3966C:  dw C39674       ; EQUIP
         dw C39685       ; OPTIMUM
         dw C3968E       ; RMOVE
         dw C3969F       ; EMPTY

; Handle "EQUIP" selection in Equip menu
C39674:  JSR C39614      ; Switch windows
         JSR C3964F      ; Draw blue "EQUIP"
         JSR C38E6C      ; Load navig data
         JSR C38E75      ; Relocate cursor
         LDA #$55        ; C3/9884
         STA $26         ; Next: Slot choice
         RTS

; Handle "OPTIMUM" selection in Equip menu
C39685:  JSR C396F0      ; Optimize gear
         JSR C3911B      ; Redo text, status
         STZ $4D         ; Cursor: "USE"
         RTS

; Handle "RMOVE" selection in Equip menu
C3968E:  JSR C39614      ; Switch windows
         JSR C39656      ; Draw blue "REMOVE"
         JSR C38E6C      ; Load navig data
         JSR C38E75      ; Relocate cursor
         LDA #$56        ; C3/98CF
         STA $26         ; Next: Slot choice
         RTS

; Handle "EMPTY" selection in Equip menu
C3969F:  JSR C396A8      ; Remove gear
         JSR C3911B      ; Redo text, status
         STZ $4D         ; Cursor: "USE"
         RTS

; Remove character's equipment
C396A8:  JSR C393F2      ; Define Y
         LDA $001F,Y     ; R-Hand item
         JSR C39D5E      ; Put in stock
         LDA $0020,Y     ; L-Hand item
         JSR C39D5E      ; Put in stock
         LDA $0021,Y     ; Helmet
         JSR C39D5E      ; Put in stock
         LDA $0022,Y     ; Armor
         JSR C39D5E      ; Put in stock
         LDA #$FF        ; Empty item
         STA $001F,Y     ; Clear R-Hand
         STA $0020,Y     ; Clear L-Hand
         STA $0021,Y     ; Clear helmet
         STA $0022,Y     ; Clear armor
         RTS

; Optimize member's equipment (event command)
C396D2:  JSR C36915      ; Get party info
         TDC             ; Clear A
         TAX             ; Member slot: 1
         LDA $0201       ; Actor to equip
C396DA:  CMP $69,X       ; In member slot?
         BEQ C396E6      ; Branch if so
         INX             ; Member slot +1
         CPX #$0004      ; Done 4 members?
         BNE C396DA      ; Loop if not
C396E4:  BRA C396E4      ; Freeze game...
C396E6:  TXA             ; Member slot
         STA $28         ; Memorize it
         JSR C39110      ; ...
         JSR C396F0      ; Optimize gear
         RTL

; Optimize character's equipment
C396F0:  JSR C39110      ; Get gear FX
         JSR C396A8      ; Remove gear
         JSR C393F2      ; Actor's address
         STY $F3         ; Memorize it
         LDA $11D8       ; Gear effects
         AND #$08        ; Gauntlet?
         BEQ C3971A      ; Branch if not

; Fork: Put a two-handed weapon in R-Hand
C39702:  STZ $4B         ; ...
         JSR C39B59      ; ...
         JSR C39795      ; Get valid items
         JSR C3A150      ; Sort by power
         JSR C3983F      ; Pick 2H weapon
         LDY $F3         ; Actor's address
         STA $001F,Y     ; Set R-Hand item
         JSR C39D97      ; Adjust stock
         BRA C3976B      ; Handle helmet

; Fork: Put a weapon in R-Hand
C3971A:  STZ $4B         ; ...
         JSR C39B59      ; ...
         JSR C39795      ; Get valid items
         JSR C3A150      ; Sort by power
         LDY $F3         ; Actor's address
         JSR C39819      ; Pick a weapon
         STA $001F,Y     ; Put in R-Hand
         JSR C39D97      ; Adjust stock
         LDA $11D8       ; Gear effects
         AND #$10        ; Genji Glove?
         BNE C39751      ; Branch if so

; Fork: Put a shield in L-Hand
C39737:  LDA #$01        ; ...
         STA $4B         ; ...
         JSR C39B59      ; ...
         JSR C397D7      ; Get valid items
         JSR C3A150      ; Sort by defense
         LDY $F3         ; Actor's address
         JSR C39819      ; Pick a shield
         STA $0020,Y     ; Put in L-Hand
         JSR C39D97      ; Adjust stock
         BRA C3976B      ; Handle helmet

; Fork: Put a weapon in L-Hand
C39751:  LDA #$01        ; ...
         STA $4B         ; ...
         JSR C39B59      ; ...
         JSR C39795      ; Get valid items
         JSR C3A150      ; Sort by power
         LDY $F3         ; Actor's address
         JSR C39819      ; Pick a weapon
         STA $0020,Y     ; Put in L-Hand
         JSR C39D97      ; Adjust stock
         BRA C3976B      ; ...

; Fork: Optimize helmet
C3976B:  LDA #$02        ; Target: Head
         STA $4B         ; Set body part
         JSR C39B59      ; Get valid items
         JSR C3A150      ; Sort by defense
         LDY $F3         ; Actor's address
         JSR C39819      ; Choose helmet
         STA $0021,Y     ; Put on actor
         JSR C39D97      ; Adjust stock

; Fork: Optimize armor
C39780:  LDA #$03        ; Target: Torso
         STA $4B         ; Set body part
         JSR C39B59      ; Get valid items
         JSR C3A150      ; Sort by defense
         LDY $F3         ; Actor's address
         JSR C39819      ; Choose armor
         STA $0022,Y     ; Put on actor
         JMP C39D97      ; Adjust stock

; Compile compatible weapons for Optimum
C39795:  JSR C39C2A      ; Init list
         JSR C39C41      ; Define compat
         LDX $00         ; Clear X
         TXY             ; Item slot: 1
C3979E:  TDC             ; Clear A
         LDA $1869,Y     ; Item in slot
         CMP #$FF        ; None?
         BEQ C397C8      ; Skip if so
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85000,X   ; Properties
         AND #$07        ; Get class
         CMP #$01        ; Weapon?
         BNE C397C8      ; Skip if not
         REP #$20        ; 16-bit A
         LDA $D85001,X   ; Compatibility
         BIT $E7         ; Actor can use?
         BEQ C397C8      ; Skip if not
         SEP #$20        ; 8-bit A
         TYA             ; Item slot
         STA $2180       ; Add to list
         INC $E0         ; List size +1
C397C8:  SEP #$20        ; 8-bit A
         INY             ; Item slot +1
         CPY #$00FF      ; Done 255?
         BNE C3979E      ; Loop if not
         LDA $E0         ; List size
         STA $7E9D89     ; Save to list
         RTS

; Compile compatible shields for Optimum
C397D7:  JSR C39C2A      ; Init list
         JSR C39C41      ; Define compat
         LDX $00         ; Clear X
         TXY             ; Item slot: 1
C397E0:  TDC             ; Clear A
         LDA $1869,Y     ; Item in slot
         CMP #$FF        ; None?
         BEQ C3980A      ; Skip if so
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85000,X   ; Properties
         AND #$07        ; Get class
         CMP #$03        ; Shield?
         BNE C3980A      ; Skip if not
         REP #$20        ; 16-bit A
         LDA $D85001,X   ; Compatibility
         BIT $E7         ; Actor can use?
         BEQ C3980A      ; Skip if not
         SEP #$20        ; 8-bit A
         TYA             ; Item slot
         STA $2180       ; Add to list
         INC $E0         ; List size +1
C3980A:  SEP #$20        ; 8-bit A
         INY             ; Item slot +1
         CPY #$00FF      ; Done 255?
         BNE C397E0      ; Loop if not
         LDA $E0         ; List size
         STA $7E9D89     ; Save to list
         RTS

; Select first non-excluded item in sorted list of compatible gear
C39819:  PHY             ; Save Y
         PHB             ; Save DB
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         TDC             ; Clear A
         TAY             ; RAM index: 0
C39821:  TDC             ; Clear A
         TAX             ; ROM index: 0
C39823:  PHX             ; Save index
         TDC             ; ...
         LDA $9D8A,Y     ; Stock slot
         TAX             ; Index it
         LDA $1869,X     ; Item in slot
         PLX             ; ROM index
         CMP $ED82E4,X   ; Excluded?
         BEQ C3983C      ; Skip if so
         INX             ; ROM index +1
         CPX #$000A      ; Tested 10?
         BNE C39823      ; Loop if not
         PLB             ; Restore DB
         PLY             ; Restore Y
         RTS             ; Exit
C3983C:  INY             ; RAM index +1
         BRA C39821      ; Try next item

; Exclusions: Cursed Shld, Thornlet, Imp set, Atma Weapon, Drainer, Soul Sabre, Heal Rod


; Select first two-handed weapon from sorted list of compatible gear
C3983F:  LDA $7E9D89     ; List size
         BEQ C39881      ; Branch if 0
         STA $CB         ; Memorize it
         STZ $CC         ; Clear its HB
         TDC             ; Clear A
         TAY             ; RAM index: 0
C3984B:  TDC             ; Clear A
         TAX             ; ROM index: 0
C3984D:  PHX             ; Save index
         TDC             ; ...
         TYX             ; RAM index
         LDA $7E9D8A,X   ; Stock slot
         TAX             ; Index it
         LDA $1869,X     ; Item in slot
         PLX             ; ROM index
         CMP $ED82E4,X   ; Excluded?
         BEQ C39878      ; Skip if so
         INX             ; ROM index +1
         CPX #$000A      ; Tested 10?
         BNE C3984D      ; Loop if not
         STA $C9         ; Save item
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85013,X   ; Properties
         AND #$40        ; 2-hand OK?
         BEQ C39878      ; Skip if not
         LDA $C9         ; Item
         RTS

; Fork: Try next weapon, ignore Gauntlet if no valid options
C39878:  INY             ; RAM index +1
         CPY $CB         ; End of list?
         BNE C3984B      ; Loop if not
         JSR C39819      ; Pick 1H weapon
         RTS

; Fork: Default to empty item
C39881:  LDA #$FF        ; Empty item
         RTS

; 55: Handle selection of gear slot to fill
C39884:  JSR C38E72      ; Handle D-Pad
         JSR C39975      ; Recolor hand names
         LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C398B4      ; Branch if not
         JSR C30EB2      ; Sound: Click
         LDA $4E         ; Cursor row
         STA $5F         ; Set body slot
         LDA #$57        ; C3/990F
         STA $26         ; Next: Item list
         JSR C39B59      ; Build item list
         JSR C3A150      ; Sort it by power
         JSR C39AEB      ; Cursor & Scrollbar
         LDA #$55        ; Return here if..
         STA $27         ; ..list is empty
         JSR C39233      ; Draw stat preview
         JSR C36A15      ; Blank item list
         JSR C31368      ; Refresh screen
         JMP C39CAC      ; Draw item list

; Fork: Handle B
C398B4:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C398C8      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         JSR C38E50      ; Load navig data
         JSR C38E59      ; Relocate cursor
         LDA #$36        ; C3/9621
         STA $26         ; Next: Option list
         RTS

; Fork: Handle L and R, prepare for menu reset
C398C8:  LDA #$7E        ; C3/1BE5
         STA $E0         ; Set init command
         JMP C32022      ; Handle L and R

; 56: Handle manual gear removal
C398CF:  JSR C38E72      ; Handle D-Pad
         LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C398F4      ; Branch if not
         JSR C30EB2      ; Sound: Click
         JSR C393F2      ; Actor's address
         REP #$21        ; 16-bit A; C-
         TYA             ; Move it to A
         SEP #$20        ; 8-bit A
         ADC $4B         ; Add cursor slot
         TAY             ; Index sum
         LDA $001F,Y     ; Item in slot
         JSR C39D5E      ; Put in stock
         LDA #$FF        ; Empty item
         STA $001F,Y     ; Clear gear slot
         JSR C3911B      ; Redo text, status

; Fork: Handle B
C398F4:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C39908      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         JSR C38E50      ; Load navig data
         JSR C38E59      ; Relocate cursor
         LDA #$36        ; C3/9621
         STA $26         ; Next: Option list
         RTS

; Fork: Handle L and R, prepare for menu reset
C39908:  LDA #$7F        ; C3/1BF3
         STA $E0         ; Set init command
         JMP C32022      ; Handle L and R

; 57: Handle gear browsing
C3990F:  JSR C39AD3      ; Handle navigation
         JSR C39233      ; Draw stat preview
         LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C39944      ; Branch if not
         JSR C39A42      ; On a gray item?
         BCC C3996E      ; Fail if so
         JSR C30EB2      ; Sound: Click
         LDA $001F,Y     ; Item to unequip
         CMP #$FF        ; None?
         BEQ C3992D      ; Branch if so
         JSR C39D5E      ; Put in stock
C3992D:  TDC             ; Clear A
         LDA $4B         ; Gear list slot
         TAX             ; Index it
         LDA $7E9D8A,X   ; Inventory slot
         TAX             ; Index it
         LDA $1869,X     ; Item in slot
         STA $001F,Y     ; Equip on actor
         JSR C39D97      ; Adjust stock
         JSR C3911B      ; Redo text, status
         BRA C3994D      ; Exit gear list

; Fork: Handle B
C39944:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C3996D      ; Exit if not
         JSR C30EA9      ; Sound: Cursor
C3994D:  JSR C39C87      ; Clear stat preview
         REP #$20        ; 16-bit A
         LDA #$0100      ; BG1 H-Shift: 256
         STA $7E9BD0     ; Hide gear list
         SEP #$20        ; 8-bit A
         LDA #$C1        ; Top cursor: Off
         TRB $46         ; Scrollbar: Off
         JSR C38E6C      ; Load navig data
         LDA $5F         ; Former position
         STA $4E         ; Set cursor row
         JSR C38E75      ; Relocate cursor
         LDA #$55        ; C3/9884
         STA $26         ; Next: Body parts
C3996D:  RTS

; Fork: Invalid selection
C3996E:  JSR C30EC0      ; Play buzzer
         JSR C3305D      ; Pixelate screen
         RTS

; Draw "R-hand" and "L-hand" in Equip menu
C39975:  LDA $11D8       ; Gear effects
         AND #$08        ; Gauntlet?
         BEQ C3998F      ; Branch if not
         JSR C393F2      ; Define Y
         LDA $001F,Y     ; R-Hand item
         CMP #$FF        ; None?
         BEQ C399A6      ; Branch if so
         LDA $0020,Y     ; L-Hand item
         CMP #$FF        ; None?
         BEQ C399CA      ; Branch if so
         BRA C3998F      ; ...

; Fork: Draw both hands in blue
C3998F:  LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         JSR C39998      ; Draw "R-hand"
         BRA C3999F      ; Draw "L-hand"

; Sub: Draw "R-hand"
C39998:  LDY #C3A2BA     ; Text pointer
         JSR C302F9      ; Draw "R-hand"
         RTS

; Sub: Draw "L-hand"
C3999F:  LDY #C3A2C3     ; Text pointer
         JSR C302F9      ; Draw "L-hand"
         RTS

; Fork: Check if L-Hand also empty
C399A6:  LDA $0020,Y     ; L-Hand item
         CMP #$FF        ; None?
         BNE C399AF      ; Branch if not
         BRA C3998F      ; Draw both in blue

; Fork: Check if two-handed weapon in L-Hand
C399AF:  JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85013,X   ; Properties
         AND #$40        ; 2-hand OK?
         BEQ C3998F      ; Blue x2 if not
         LDA #$24        ; Palette 1
         STA $29         ; Color: Gray
         JSR C39998      ; Draw "R-hand"
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         BRA C3999F      ; Draw "L-hand"

; Fork: Check if two-handed weapon in R-Hand
C399CA:  LDA $001F,Y     ; R-Hand item
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85013,X   ; Properties
         AND #$40        ; 2-hand OK?
         BEQ C3998F      ; Blue x2 if not
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         JSR C39998      ; Draw "R-hand"
         LDA #$24        ; Palette 1
         STA $29         ; Color: Gray
         BRA C3999F      ; Draw "L-hand"

; Define Bat.Pwr mode (normal, doubled, or combined hands)
C399E8:  STZ $CD         ; Genji mode off
         LDA $11D8       ; Gear effects
         AND #$10        ; Genji Glove?
         BEQ C399F3      ; Branch if not
         INC $CD         ; Pwr: Merge hands
C399F3:  STZ $A1         ; Power x2: Off
         LDA $11D8       ; Gear effects
         AND #$08        ; Gauntlet?
         BEQ C39A0C      ; Exit if not
         LDA $001F,Y     ; R-Hand item
         CMP #$FF        ; None?
         BEQ C39A0E      ; Branch if so
         LDA $0020,Y     ; L-Hand item
         CMP #$FF        ; None?
         BEQ C39A2B      ; Branch if so
         BRA C39A0C      ; ...
C39A0C:  SEC             ; ...
         RTS

; Fork: Check if L-Hand also empty
C39A0E:  LDA $0020,Y     ; L-Hand item
         CMP #$FF        ; None?
         BNE C39A17      ; Branch if not
         BRA C39A0C      ; Exit

; Fork: Check if two-handed weapon in L-Hand
C39A17:  JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85013,X   ; Properties
         AND #$40        ; 2-hand OK?
         BEQ C39A0C      ; Exit if not
         CLC             ; ...
         LDA #$01        ; Power: x2
         STA $A1         ; Set Pwr mode
         RTS

; Fork: Check if two-handed weapon in R-Hand
C39A2B:  LDA $001F,Y     ; R-Hand item
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85013,X   ; Properties
         AND #$40        ; 2-hand OK?
         BEQ C39A0C      ; Exit if not
         CLC             ; ...
         LDA #$01        ; Power: x2
         STA $A1         ; Set Pwr mode
         RTS

; Check if pointing at grayed out gear
C39A42:  JSR C39A4A      ; Actor address
         TDC             ; Clear A
         LDA $4B         ; Gear list slot
         BRA C39A56      ; Analyze item

; Load address to selected body slot
C39A4A:  JSR C393F2      ; Actor's address
         REP #$21        ; 16-bit A; C-
         TYA             ; Move it to A
         SEP #$20        ; 8-bit A
         ADC $5F         ; Add body slot
         TAY             ; Move it to Y
         RTS

; Determine whether gear list entry is disabled
C39A56:  PHY             ; ...
         TAX             ; Gear list slot
         LDA $7E9D8A,X   ; Inventory slot
         TAX             ; Index it
         LDA $1869,X     ; Item in slot
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85000,X   ; Properties
         AND #$07        ; Get class
         STA $F6         ; Memorize it
         PLY             ; ...
         LDA $5F         ; Body slot
         CMP #$02        ; Head or body?
         BCS C39ACF      ; Enable if so
         CMP #$01        ; L-Hand/relic 2?
         BEQ C39AA5      ; Branch if so

; Fork: For R-Hand or relic 1
C39A79:  LDA $0020,Y     ; L-Hand item
         CMP #$FF        ; None?
         BEQ C39A97      ; Enable if so
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85000,X   ; Properties
         AND #$07        ; Get class
         CMP #$03        ; Shield?
         BEQ C39A99      ; Branch if so
         LDA $11D8       ; Gear effects
         AND #$10        ; Genji Glove?
         BEQ C39A99      ; Branch if not
C39A97:  SEC             ; Set to enable
         RTS

; Fork: Prevent two shields or weapons
C39A99:  LDA $D85000,X   ; L-Hand's specs
         AND #$07        ; Get item class
         CMP $F6         ; Like list item?
         BEQ C39AD1      ; Disable if so
         SEC             ; Set to enable
         RTS

; Fork: For L-Hand or relic 2
C39AA5:  LDA $001E,Y     ; R-Hand item
         CMP #$FF        ; None?
         BEQ C39AC3      ; Enable if so
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85000,X   ; Properties
         AND #$07        ; Get class
         CMP #$03        ; Shield?
         BEQ C39AC5      ; Branch if so
         LDA $11D8       ; Gear effects
         AND #$10        ; Genji Glove?
         BEQ C39AC5      ; Branch if not
C39AC3:  SEC             ; Set to enable
         RTS

; Fork: Prevent two shields or weapons
C39AC5:  LDA $D85000,X   ; R-Hand's specs
         AND #$07        ; Get item class
         CMP $F6         ; Like list item?
         BEQ C39AD1      ; Disable if so
C39ACF:  SEC             ; Set to enable
         RTS

; Fork: Disable listed item
C39AD1:  CLC             ; Set to disable
         RTS

; Handle D-Pad plus L and R for gear browsing
C39AD3:  LDA $7E9D89     ; List size
         CMP #$0A        ; Over 9 items?
         BCS C39ADE      ; Branch if so
         JMP C38E9D      ; Handle D-Pad

; Fork: Scrollable list
C39ADE:  LDA #$05        ; List type: Gear
         STA $2A         ; Set redraw mode
         JSR C31F64      ; Handle L and R
         BCS C39AEA      ; Exit if pushed
         JMP C38E8E      ; Handle D-Pad
C39AEA:  RTS

; Initialize cursor data for list of available gear
C39AEB:  LDA $7E9D89     ; Number of items
         BEQ C39B0C      ; Exit if none
         CMP #$0A        ; Over 9?
         BCS C39B06      ; Branch if so
         JSR C39DC4      ; Duplicate cursor
         STZ $4A         ; List scroll: 0
         JSR C38E97      ; Load navig data
         LDA $7E9D89     ; Number of items
         STA $54         ; Set cursor limit
         JMP C38EA0      ; Relocate cursor

; Fork: Scrollable list
C39B06:  JSR C39DC4      ; Duplicate cursor
         JSR C39B0D      ; Move cursor; bar
C39B0C:  RTS

; Initialize cursor data for scrollable gear list
C39B0D:  STZ $4A         ; List scroll: 0
         JSR C30933      ; Create scrollbar
         REP #$20        ; 16-bit A
         LDA #$0060      ; Y: 96
         STA $7E34CA,X   ; Set scrollbar's
         LDA #$6000      ; Bar range: 60 px
         STA $4204       ; Set dividend
         SEP #$20        ; 8-bit A
         LDA $7E9D89     ; Number of items
         SEC             ; Prepare SBC
         SBC #$09        ; Deduct page size
         STA $4206       ; Set divisor
         NOP
         NOP
         NOP
         NOP
         NOP
         REP #$20        ; 16-bit A
         LDA $4214       ; Quotient
         STA $7E354A,X   ; Set bar's V-Spd
         SEP #$20        ; 8-bit A
         LDY $00         ; Clear Y
         STY $4F         ; List col/row: 1
         JSR C38E88      ; Load navig data
         JSR C38E91      ; Relocate cursor
         LDA $7E9D89     ; Number of items
         SEC             ; Prepare SBC
         SBC #$09        ; Deduct page size
         STA $5C         ; Set scroll limit
         LDA #$09        ; Onscreen rows: 9
         STA $5A         ; Set rows per page
         LDA #$01        ; Onscreen cols: 1
         STA $5B         ; Set cols per page
         RTS

; Compile compatible gear for actor's body part
C39B59:  JSR C39C2A      ; Init list
         JSR C39C41      ; Define compat
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDA $4B         ; Body part
         CMP #$02        ; Head?
         BEQ C39BB2      ; Branch if so
         CMP #$03        ; Armor?
         BEQ C39B6F      ; Branch if so
         BRA C39B72      ; Handle hands
C39B6F:  JMP C39BEE      ; Handle torso

; Fork: Weapons and shields
C39B72:  LDX $00         ; Clear X...
         TXY             ; Item slot: 1
C39B75:  TDC             ; Clear A
         LDA $1869,Y     ; Item in slot
         CMP #$FF        ; None?
         BEQ C39BA3      ; Skip if so
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85000,X   ; Properties
         AND #$07        ; Get class
         CMP #$01        ; Weapon?
         BEQ C39B91      ; Branch if so
         CMP #$03        ; Shield?
         BNE C39BA3      ; Skip if not
C39B91:  REP #$20        ; 16-bit A
         LDA $D85001,X   ; Compatibility
         BIT $E7         ; Actor can use?
         BEQ C39BA3      ; Skip if not
         SEP #$20        ; 8-bit A
         TYA             ; Item slot
         STA $2180       ; Add to list
         INC $E0         ; List size +1
C39BA3:  SEP #$20        ; 8-bit A
         INY             ; Item slot +1
         CPY #$00FF      ; Done 255?
         BNE C39B75      ; Loop if not
         LDA $E0         ; List size
         STA $7E9D89     ; Save to list
         RTS

; Fork: Helmet list
C39BB2:  LDX $00         ; Clear X...
         TXY             ; Item slot: 1
C39BB5:  TDC             ; Clear A
         LDA $1869,Y     ; Item in slot
         CMP #$FF        ; None?
         BEQ C39BDF      ; Skip if so
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85000,X   ; Properties
         AND #$07        ; Get class
         CMP #$04        ; Helmet?
         BNE C39BDF      ; Skip if not
         REP #$20        ; 16-bit A
         LDA $D85001,X   ; Compatibility
         BIT $E7         ; Actor can use?
         BEQ C39BDF      ; Skip if not
         SEP #$20        ; 8-bit A
         TYA             ; Item slot
         STA $2180       ; Add to list
         INC $E0         ; List size +1
C39BDF:  SEP #$20        ; 8-bit A
         INY             ; Item slot +1
         CPY #$00FF      ; Done 255?
         BNE C39BB5      ; Loop if not
         LDA $E0         ; List size
         STA $7E9D89     ; Save to list
         RTS

; Fork: Armor list
C39BEE:  LDX $00         ; Clear X...
         TXY             ; Item slot: 1
C39BF1:  TDC             ; Clear A
         LDA $1869,Y     ; Item in slot
         CMP #$FF        ; None?
         BEQ C39C1B      ; Skip if so
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85000,X   ; Properties
         AND #$07        ; Get class
         CMP #$02        ; Armor?
         BNE C39C1B      ; Skip if not
         REP #$20        ; 16-bit A
         LDA $D85001,X   ; Compatibility
         BIT $E7         ; Actor can use?
         BEQ C39C1B      ; Skip if not
         SEP #$20        ; 8-bit A
         TYA             ; Item slot
         STA $2180       ; Add to list
         INC $E0         ; List size +1
C39C1B:  SEP #$20        ; 8-bit A
         INY             ; Item slot +1
         CPY #$00FF      ; Done 255?
         BNE C39BF1      ; Loop if not
         LDA $E0         ; List size
         STA $7E9D89     ; Save to list
         RTS

; Initialize list of compatible gear
C39C2A:  LDX $00         ; Index: 0
         LDA #$FF        ; Item slot 256
C39C2E:  STA $7E9D8A,X   ; Add to list
         INX             ; Index +1
         CPX #$0009      ; Done 9 times?
         BNE C39C2E      ; Loop if not
         LDX #$9D8A      ; 7E/9D8A
         STX $2181       ; Set WRAM LBs
         STZ $E0         ; List size: 0
         RTS

; Defaulting to item slot 256, which is unused in the SNES versions, provides a fallback
; for Optimum in case the list is empty or contains only banned items such as Cursed Shld.


; Define gear compatibility for actor
C39C41:  JSR C393F2      ; Define Y
         TDC             ; ...
         LDA $0000,Y     ; Actor
C39C48:  ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C39C67,X  ; Compat bit
         STA $E7         ; Memorize it
         SEP #$20        ; 8-bit A
         LDA $11D8       ; Gear effects
         AND #$20        ; Merit Award?
         BEQ C39C66      ; Exit if not
         REP #$20        ; 16-bit A
         LDA $E7         ; Actor's bit
         ORA #$8000      ; Add award's
         STA $E7         ; Save changes
         SEP #$20        ; 8-bit A
C39C66:  RTS

; Bitfield for actor slots
C39C67:  dw $0001        ; Terra
         dw $0002        ; Locke
         dw $0004        ; Cyan
         dw $0008        ; Shadow
         dw $0010        ; Edgar
         dw $0020        ; Sabin
         dw $0040        ; Celes
         dw $0080        ; Strago
         dw $0100        ; Relm
         dw $0200        ; Setzer
         dw $0400        ; Mog
         dw $0800        ; Gau
         dw $1000        ; Gogo
         dw $2000        ; Umaro
         dw $4000        ; Guest 1
         dw $8000        ; Guest 2

; Erase projected stats in Equip or Relic menu
C39C87:  TDC             ; Clear A
         TAX             ; 1st: Vigor
         LDY #$0009      ; Stats: 9
         REP #$20        ; 16-bit A
C39C8E:  STA $7E7CBF,X   ; Clear hundreds
         INX             ; Index +1
         INX             ; Index +1
         STA $7E7CBF,X   ; Clear tens
         INX             ; Index +1
         INX             ; Index +1
         STA $7E7CBF,X   ; Clear ones
         INX             ; Index +1
         INX             ; Index +1
         TXA             ; Tilemap ptr
         CLC             ; Prepare ADC
         ADC #$007A      ; Row +2, col -3
         TAX             ; Reindex it
         DEY             ; One less stat
         BNE C39C8E      ; Loop till last
         SEP #$20        ; 8-bit A
         RTS

; Draw and reveal list of available gear for body part
C39CAC:  LDA $7E9D89     ; Empty list?
         BEQ C39CDD      ; Abort if so
         JSR C383F7      ; Define $E5, $E6
         TDC             ; Clear A
         LDA $7E9D89     ; List size
         CMP #$09        ; Over 8 items?
         BCC C39CC0      ; Branch if not
         LDA #$09        ; Rows left: 9
C39CC0:  TAY             ; Put in Y...
C39CC1:  PHY             ; Memorize it
         JSR C39CE2      ; Draw item name
         INC $E5         ; List slot +1
         LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         INC A           ; Go 1 row down
         AND #$1F        ; Stay in limits
         STA $E6         ; Save changes
         PLY             ; Rows left
         DEY             ; One less left
         BNE C39CC1      ; Loop till last
         REP #$20        ; 16-bit A
         TDC             ; BG1 H-Shift: 0
         STA $7E9BD0     ; Unhide gear list
         SEP #$20        ; 8-bit A
         RTS             ; Exit
C39CDD:  LDA $27         ; Old menu mode
         STA $26         ; Set as current
         RTS

; Draw name of item from list of available gear
C39CE2:  JSR C39A4A      ; Actor's address
         TDC             ; Clear A
         LDA $E5         ; Gear list slot
         JSR C39A56      ; Gray out item?
         BCS C39CF1      ; Branch if not
         LDA #$28        ; Color: Gray
         BRA C39CF3      ; Skip a line
C39CF1:  LDA #$20        ; Color: User's
C39CF3:  STA $29         ; Set palette
         LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         LDX #$0002      ; X: 2
         JSR C3809F      ; Compute map ptr
         REP #$20        ; 16-bit A
         TXA             ; ...
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $E5         ; Gear list slot
         TAY             ; Put it in Y
         JSR C39D11      ; Load item name
         JMP C37FD9      ; Draw item name

; Load name of item from list of available gear
C39D11:  LDX #$9E8B      ; 7E/9E8B
         STX $2181       ; Set WRAM LBs
C39D17:  LDA $4212       ; PPU status
         AND #$40        ; H-Blank?
         BEQ C39D17      ; Loop if not
         TYX             ; Gear list slot
         TDC             ; ...
         LDA $7E9D8A,X   ; Inventory slot
         TAY             ; Index it
         LDA $1869,Y     ; Item in slot
         CMP #$FF        ; None?
         BEQ C39D4F      ; Blank if so
         STA $211B       ; Set matrix A LB
         STZ $211B       ; Clear HB
         LDA #$0D        ; Name data size
         STA $211C       ; Set matrix B
         STA $211C       ; ...
         LDX $2134       ; Index product
         LDY #$000D      ; Letters: 13
C39D40:  LDA $D2B300,X   ; Letter
         STA $2180       ; Add to string
         INX             ; Point to next
         DEY             ; One less left
         BNE C39D40      ; Loop till last
         STZ $2180       ; End string
         RTS

; Fork: Blank item name
C39D4F:  LDY #$000D      ; Spaces: 13
         LDA #$FF        ; Space char
C39D54:  STA $2180       ; Add to string
         DEY             ; One less left
         BNE C39D54      ; Loop till last
         STZ $2180       ; End string
         RTS

; Add item to inventory
C39D5E:  PHY             ; Save Y
         STA $E0         ; Set item to add
         LDY $00         ; Item slot: 1
C39D63:  CMP $1869,Y     ; Slot holds it?
         BEQ C39D8A      ; Qty +1 if so
         CMP #$FF        ; Empty item?
         BEQ C39D95      ; Exit if so
         INY             ; Item slot +1
         CPY #$0100      ; Done all 256?
         BNE C39D63      ; Loop if not

; Fork: Find an empty slot
C39D72:  LDY $00         ; Item slot: 1
C39D74:  LDA $1869,Y     ; Item in slot
         CMP #$FF        ; None?
         BEQ C39D7E      ; Replace if so
         INY             ; Item slot +1
         BRA C39D74      ; Try next slot

; Fork: Put item in empty slot
C39D7E:  LDA #$01        ; Quantity: 1
         STA $1969,Y     ; Assign to slot
         LDA $E0         ; Item to add
         STA $1869,Y     ; Put in slot
         BRA C39D95      ; Exit

; Fork: Quantity +1
C39D8A:  LDA $1969,Y     ; Quantity owned
         CMP #$63        ; 99?
         BEQ C39D95      ; Exit if so
         INC A           ; Quantity +1
         STA $1969,Y     ; Save changes
C39D95:  PLY             ; Restore Y
         RTS

; Remove item from inventory
C39D97:  PHY             ; Save Y
         STA $E0         ; ...
         LDY $00         ; Item slot: 1
C39D9C:  CMP $1869,Y     ; Slot holds it?
         BEQ C39DA9      ; Branch if so
         INY             ; Item slot +1
         CPY #$0100      ; Done all 256?
         BNE C39D9C      ; Loop if not
         PLY             ; Restore Y
         RTS

; Fork: Quantity -1
C39DA9:  LDA $1969,Y     ; Quantity
         CMP #$01        ; One?
         BEQ C39DB9      ; Delete if so
         LDA $1969,Y     ; ...
         DEC A           ; Quantity -1
         STA $1969,Y     ; Save changes
         BRA C39DC2      ; Exit

; Fork: Clear item slot
C39DB9:  TDC             ; Clear A
         STA $1969,Y     ; Quantity: 0
         LDA #$FF        ; Empty item
         STA $1869,Y     ; Put in slot
C39DC2:  PLY             ; Restore Y
         RTS

; Duplicate cursor before browsing gear
C39DC4:  LDA #$02        ; Min slot: 16
         LDY #C39DDD     ; C3/9DDD
         JSR C31173      ; Queue OAM fn
         REP #$20        ; 16-bit A
         LDA $55         ; Cursor's X
         STA $7E33CA,X   ; Set dupe's
         LDA $57         ; Cursor's Y
         STA $7E344A,X   ; Set dupe's
         SEP #$20        ; 8-bit A
         RTS

; Update cursor indicating selected gear slot
C39DDD:  TAX             ; Index mode
         JMP (C39DE1,X)  ; Handle mode

; Jump table for the above
C39DE1:  dw C39DE5       ; Initialize cursor
         dw C39E00       ; Sustain cursor

; Mode 0: Initialize cursor
C39DE5:  LDX $2D         ; Queue index
         LDA #$01        ; Dupe: Sustain
         TSB $46         ; Set menu flag
         REP #$20        ; 16-bit A
         LDA #C3088D     ; Anim table ptr
         STA $32C9,X     ; Set sprite's
         SEP #$20        ; 8-bit A
         LDA #$C3        ; Bank: C3
         STA $35CA,X     ; Set ptr HB
         JSR C31206      ; Set pose timer
         INC $3649,X     ; Mode +1

; Mode 1: Sustain cursor
C39E00:  LDA $46         ; Menu flags
         BIT #$01        ; Remove dupe?
         BEQ C39E0D      ; Delete if so
         LDX $2D         ; Queue index
         JSR C31221      ; Define OAM
         SEC             ; Set to requeue
         RTS             ; Exit
C39E0D:  CLC             ; Set to dequeue
         RTS

; Set to upload text tilemaps for Equip menu
C39E0F:  JSR C39E23      ; Queue BG3 upload
         BRA C39E37      ; Queue BG1 upload

; Set to upload text tilemaps for Relic menu
C39E14:  JSR C39E37      ; Queue BG1 upload
         LDA $021E       ; Frame counter
         AND #$01        ; Odd value?
         BEQ C39E20      ; Favor desc if so
         BRA C39E23      ; Queue stats upload
C39E20:  JMP C3A991      ; Queue desc upload

; Set to upload BG3 tilemaps A and upper B
C39E23:  LDY #$4000      ; $8000
         STY $1B         ; Set VRAM ptr
         LDY #$7849      ; 7E/7849
         STY $1D         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $1F         ; Set src HB
         LDY #$0880      ; Bytes: 2176
         STY $19         ; Set data size
         RTS

; Set to upload BG1 tilemap A
C39E37:  LDY #$0000      ; $0000
         STY $14         ; Set VRAM ptr
         LDY #$3849      ; 7E/3849
         STY $16         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $18         ; Set src HB
         LDY #$0800      ; Bytes: 2048
         STY $12         ; Set data size
         RTS

; 58: Initialize Relic menu
C39E4B:  JSR C39E50      ; Init variables
         BRA C39E6F      ; Draw menu, etc.

; Initialize variables for Relic menu
C39E50:  JSR C3352F      ; Reset/Stop stuff
         JSR C36A08      ; Set Win1 bounds
         STZ $4A         ; List scroll: 0
         STZ $49         ; Top BG1 WR row: 1
         LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         STZ $99         ; Unmark Reequip
         JSR C31B99      ; Queue desc anim
         JSR C394B6      ; Set to shift text
         JSR C38EBD      ; Load navig data
         JSR C38EC6      ; Relocate cursor
         JMP C307B0      ; Queue cursor OAM

; Draw Relic menu, memorize original relics, etc.
C39E6F:  JSR C3906A      ; Draw menu, etc.
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         LDA #$59        ; C3/9EB8
         STA $27         ; Queue: Option list
         JMP C33541      ; BRT:1 + NMI

; 79: Swap actor in Relic menu, retain Equip mode
C39E7D:  JSR C39E99      ; Draw menu, etc.
         JSR C3964F      ; Draw blue "EQUIP"
         JSR C39EA8      ; Cursor & Fade-in
         LDA #$5A        ; C3/9FFD
         JMP C39EB3      ; Queue: Slot list

; 7A: Swap actor in Relic menu, retain Remove mode
C39E8B:  JSR C39E99      ; Draw menu, etc.
         JSR C39656      ; Draw blue "REMOVE"
         JSR C39EA8      ; Cursor & Fade-in
         LDA #$5C        ; C3/A10A
         JMP C39EB3      ; Queue: Slot list

; Reset Relic menu for either of the above
C39E99:  JSR C39E50      ; Init variables
         JSR C3906A      ; Draw menu, etc.
         JSR C39E37      ; Queue BG1 upload
         JSR C39E23      ; Queue BG3 upload
         JMP C39614      ; Switch windows

; Put cursor on first relic slot, trigger fade-in
C39EA8:  JSR C38ED5      ; Load navig data
         JSR C38EDE      ; Relocate cursor
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         RTS

; Queue Equip or Remove mode after actor swap in Relic menu
C39EB3:  STA $27         ; Set queued command
         JMP C33541      ; BRT:1 + NMI

; 59: Handle Relic menu options
C39EB8:  JSR C39E23      ; Queue BG3 upload
         JSR C3960C      ; Switch windows
         JSR C3905C      ; Draw options
         JSR C38EC3      ; Handle D-Pad
         LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C39ED0      ; Branch if not
         JSR C30EB2      ; Sound: Click
         JMP C39FCF      ; Handle choice

; Fork: Handle B
C39ED0:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C39EDC      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         JSR C39EEB      ; Handle Reequip

; Fork: Handle L and R, prepare for menu reset
C39EDC:  JSR C39EE6      ; Plan Reequip pos
         LDA #$58        ; C3/9E4B
         STA $E0         ; Set init command
         JMP C32022      ; Handle L and R

; Memorize menu mode for positioning Reequip warning
C39EE6:  LDA $26         ; Menu mode
         STA $D1         ; Save for Reequip
         RTS

; Test Reequip activation, select menu commands accordingly
C39EEB:  JSR C39110      ; Get gear effects
         JSR C393F2      ; Define Y
         LDA $0000,Y     ; Actor
         CMP #$0D        ; Umaro?
         BEQ C39EFF      ; Branch if so
         JSR C39F5C      ; Test Reequip
         LDA $99         ; Triggered it?
         BNE C39F06      ; Branch if so
C39EFF:  LDA #$04        ; C3/1A8A
         STA $27         ; Queue main menu
         STZ $26         ; Next: Fade-out
         RTS

; Fork: Triggered Reequip
C39F06:  LDA #$06        ; Main cursor: Off
         TRB $46         ; Set menu flag
         JSR C39E37      ; Queue BG1 upload
         JSR C39E23      ; Queue BG3 upload
         JSR C39F1C      ; Handle text, etc.
         LDA #$F0        ; Frames: 240
         STA $22         ; Set fade delay
         LDA #$6C        ; C3/9FB1
         STA $26         ; Next: Late fade
         RTS

; Handle Reequip activation
C39F1C:  JSR C3965D      ; Erase top text
         LDY #C3A40F     ; Text pointer
         JSR C302F9      ; Draw warning
         LDA $1D4E       ; Game options
         AND #$10        ; Optimum mode?
         BEQ C39F44      ; Branch if so

; Fork: Empty mode
C39F2C:  LDA #$6E        ; C3/1C26
         STA $27         ; Queue removal
         LDA $D1         ; Menu mode
         CMP #$59        ; Relic options?
         BEQ C39F3D      ; Branch if so
         LDY #C3A3FD     ; Text pointer
         JSR C302F9      ; Draw "Empty"
         RTS

; Fork: Draw "Empty" in option window
C39F3D:  LDY #C3A3EB     ; Text pointer
         JSR C302F9      ; Draw "Empty"
         RTS

; Fork: Optimum mode
C39F44:  LDA #$6D        ; C3/1C1A
         STA $27         ; Queue optimizing
         LDA $D1         ; Menu mode
         CMP #$59        ; Relic options?
         BEQ C39F55      ; Branch if so
         LDY #C3A405     ; Text pointer
         JSR C302F9      ; Draw "Optimum"
         RTS

; Fork: Draw "Optimum" in option window
C39F55:  LDY #C3A3F3     ; Text pointer
         JSR C302F9      ; Draw "Optimum"
         RTS

; Determine whether to trigger Reequip in Relic menu
C39F5C:  JSR C393F2      ; Define Y...
         LDA $0023,Y     ; Relic 1
         CMP $B0         ; Unchanged?
         BNE C39F6F      ; Branch if not
         LDA $0024,Y     ; Relic 2
         CMP $B1         ; Unchanged?
         BNE C39F6F      ; Branch if not
         BRA C39FA9      ; Reequip: No

; Fork: Compare old and new relics
C39F6F:  LDA $B0         ; Old relic 1
         CMP #$D1        ; Genji Glove?
         BEQ C39FAC      ; Trigger if so
         CMP #$D0        ; Gauntlet?
         BEQ C39FAC      ; Trigger if so
         CMP #$DA        ; Merit Award?
         BEQ C39FAC      ; Trigger if so
         LDA $B1         ; Old relic 2
         CMP #$D1        ; Genji Glove?
         BEQ C39FAC      ; Trigger if so
         CMP #$D0        ; Gauntlet?
         BEQ C39FAC      ; Trigger if so
         CMP #$DA        ; Merit Award?
         BEQ C39FAC      ; Trigger if so
         LDA $0023,Y     ; Relic 1
         CMP #$D1        ; Genji Glove?
         BEQ C39FAC      ; Trigger if so
         CMP #$D0        ; Gauntlet?
         BEQ C39FAC      ; Trigger if so
         CMP #$DA        ; Merit Award?
         BEQ C39FAC      ; Trigger if so
         LDA $0024,Y     ; Relic 2
         CMP #$D1        ; Genji Glove?
         BEQ C39FAC      ; Trigger if so
         CMP #$D0        ; Gauntlet?
         BEQ C39FAC      ; Trigger if so
         CMP #$DA        ; Merit Award?
         BEQ C39FAC      ; Trigger if so
C39FA9:  STZ $99         ; Reequip: No
         RTS

; Fork: Set to open Equip menu
C39FAC:  LDA #$01        ; Reequip: Yes
         STA $99         ; Set indicator
         RTS

; 6C: Handle delayed fade-out for Reequip
C39FB1:  LDA $22         ; Delay expired?
         BNE C39FB8      ; Branch if not
         STZ $26         ; Next: Fade-out
         RTS             ; Exit
C39FB8:  DEC $22         ; Timer -1
         LDA $08         ; No-autofire keys
         BIT #$10        ; Pushing R?
         BNE C39FCC      ; Fade if so
         LDA $08         ; ...
         BIT #$20        ; Pushing L?
         BNE C39FCC      ; Fade if so
         LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C39FCE      ; Exit if not
C39FCC:  STZ $26         ; Next: Fade-out
C39FCE:  RTS

; Handle selected option in Relic menu
C39FCF:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C39FD7,X)  ; Handle option

; Jump table for the above
C39FD7:  dw C39FDB       ; EQUIP
         dw C39FEC       ; REMOVE

; Handle "EQUIP" selection in Relic menu
C39FDB:  JSR C39614      ; Switch windows
         JSR C3964F      ; Draw blue "EQUIP"
         JSR C38ED5      ; Load navig data
         JSR C38EDE      ; Relocate cursor
         LDA #$5A        ; C3/9FFD
         STA $26         ; Next: Slot list
         RTS

; Handle "REMOVE" selection in Relic menu
C39FEC:  JSR C39614      ; Switch windows
         JSR C39656      ; Draw blue "REMOVE"
         JSR C38ED5      ; Load navig data
         JSR C38EDE      ; Relocate cursor
         LDA #$5C        ; C3/A10A
         STA $26         ; Next: Slot list
         RTS

; 5A: Handle selection of relic slot to fill
C39FFD:  JSR C39E14      ; Queue text upload
         JSR C38EDB      ; Handle D-Pad
         LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C3A033      ; Branch if not
         JSR C30EB2      ; Sound: Click
         LDA $4E         ; Cursor row
         STA $5F         ; Set body slot
         LDA #$5B        ; C3/A097
         STA $26         ; Next: Relic list
         JSR C3A051      ; Get valid items
         JSR C3A150      ; Sort by Defense
         JSR C39AEB      ; Cursor & Scrollbar
         LDA #$5A        ; Return here if..
         STA $27         ; ..list is empty
         JSR C36A15      ; Clear BG1 map A
         JSR C31368      ; Refresh screen
         JSR C39CAC      ; Draw item list
         JSR C39233      ; Draw stat preview
         JSR C39E23      ; Queue BG3 upload
         JMP C31368      ; Refresh screen

; Fork: Handle B
C3A033:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C3A047      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         JSR C38EBD      ; Load navig data
         JSR C38EC6      ; Relocate cursor
         LDA #$59        ; C3/9EB8
         STA $26         ; Next: Option list
         RTS

; Fork: Handle L and R, prepare for menu reset
C3A047:  JSR C39EE6      ; Plan Reequip pos
         LDA #$79        ; C3/9E7D
         STA $E0         ; Set init command
         JMP C32022      ; Handle L and R

; Compile compatible relics
C3A051:  JSR C39C2A      ; Init list
         JSR C39C41      ; Define compat
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDX $00         ; Clear X...
         TXY             ; Item slot: 1
C3A05E:  TDC             ; Clear A
         LDA $1869,Y     ; Item in slot
         CMP #$FF        ; None?
         BEQ C3A088      ; Skip if so
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85000,X   ; Properties
         AND #$07        ; Get class
         CMP #$05        ; Relic?
         BNE C3A088      ; Skip if not
         REP #$20        ; 16-bit A
         LDA $D85001,X   ; Compatibility
         BIT $E7         ; Actor can use?
         BEQ C3A088      ; Skip if not
         SEP #$20        ; 8-bit A
         TYA             ; Item slot
         STA $2180       ; Add to list
         INC $E0         ; List size +1
C3A088:  SEP #$20        ; 8-bit A
         INY             ; Item slot +1
         CPY #$0100      ; Done all 256?
         BNE C3A05E      ; Loop if not
         LDA $E0         ; List size
         STA $7E9D89     ; Save to list
         RTS

; 5B: Handle relic browsing
C3A097:  LDA #$10        ; Description: On
         TRB $45         ; Set menu flag
         JSR C39E14      ; Queue text upload
         JSR C39AD3      ; Handle navigation
         JSR C39233      ; Draw stat preview
         JSR C3A1D8      ; Load description

; Fork: Handle A
C3A0A7:  LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C3A0DC      ; Branch if not
         JSR C30EB2      ; Sound: Click
         JSR C393F2      ; Actor's address
         REP #$21        ; 16-bit A; C-
         TYA             ; Move it to A
         SEP #$20        ; 8-bit A
         ADC $5F         ; Add relic slot
         TAY             ; Index sum
         LDA $0023,Y     ; Relic to unequip
         CMP #$FF        ; None?
         BEQ C3A0C5      ; Branch if so
         JSR C39D5E      ; Put in stock
C3A0C5:  TDC             ; Clear A
         LDA $4B         ; Gear list slot
         TAX             ; Index it
         LDA $7E9D8A,X   ; Inventory slot
         TAX             ; Index it
         LDA $1869,X     ; Selected item
         STA $0023,Y     ; Equip on actor
         JSR C39D97      ; Reduce stock
         JSR C39131      ; Draw info; status
         BRA C3A0E5      ; Exit list

; Fork: Handle B
C3A0DC:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C3A109      ; Exit if not
         JSR C30EA9      ; Sound: Cursor
C3A0E5:  LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         JSR C39C87      ; Clear stat preview
         REP #$20        ; 16-bit A
         LDA #$0100      ; BG1 H-Shift: 256
         STA $7E9BD0     ; Hide gear list
         SEP #$20        ; 8-bit A
         LDA #$C1        ; Top cursor: Off
         TRB $46         ; Scrollbar: Off
         JSR C38ED5      ; Load navig data
         LDA $5F         ; Former position
         STA $4E         ; Set cursor row
         JSR C38EDE      ; Relocate cursor
         LDA #$5A        ; C3/9FFD
         STA $26         ; Next: Slot list
C3A109:  RTS

; 5C: Handle relic removal
C3A10A:  JSR C39E23      ; Queue BG3 upload
         JSR C38EDB      ; Handle D-Pad
         LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C3A132      ; Branch if not
         JSR C30EB2      ; Sound: Click
         JSR C393F2      ; Actor's address
         REP #$21        ; 16-bit A; C-
         TYA             ; Move it to A
         SEP #$20        ; 8-bit A
         ADC $4B         ; Add cursor slot
         TAY             ; Index sum
         LDA $0023,Y     ; Relic worn
         JSR C39D5E      ; Put in stock
         LDA #$FF        ; Empty item
         STA $0023,Y     ; Clear relic worn
         JSR C39131      ; Draw info; status

; Fork: Handle B
C3A132:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C3A146      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         JSR C38EBD      ; Load navig data
         JSR C38EC6      ; Relocate cursor
         LDA #$59        ; C3/9EB8
         STA $26         ; Next: Option list
         RTS

; Fork: Handle L and R, prepare for menu reset
C3A146:  JSR C39EE6      ; Plan Reequip pos
         LDA #$7A        ; C3/9E8B
         STA $E0         ; Set init command
         JMP C32022      ; Handle L and R

; Sort compatible gear by power after loading power ratings
C3A150:  LDX #$AC8D      ; 7E/AC8D
         STX $2181       ; Set WRAM LBs
         LDA $7E9D89     ; List size
         BEQ C3A186      ; Exit if 0
         CMP #$01        ; One item?
         BEQ C3A186      ; Exit if so
         STA $E7         ; Memorize it
         STZ $E8         ; Clear HB
         TDC             ; Clear A
         TAX             ; Gear slot: 1
         TAY             ; ...
C3A167:  LDA $7E9D8A,X   ; Inventory slot
         PHX             ; Save gear slot
         TAY             ; Index former
         LDA $1869,Y     ; Item in slot
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85014,X   ; Item's power
         STA $2180       ; Add to list
         PLX             ; Gear slot
         INX             ; Gear slot +1
         CPX $E7         ; End of list?
         BNE C3A167      ; Loop if not
         JSR C3A187      ; Sort list
C3A186:  RTS

; Sort list of compatible gear by power
C3A187:  DEC $E7         ; List size -1
         PHB             ; Save DB
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         TDC             ; Clear A
         TAY             ; Items done: 0
C3A190:  TDC             ; Clear A
         TAX             ; List slot: 1
C3A192:  LDA $AC8D,X     ; Item's power
         CMP $AC8E,X     ; Next is worse?
         BCS C3A1B7      ; Skip if not
         STA $E0         ; Memorize it
         LDA $9D8A,X     ; Item number A
         STA $E1         ; Memorize it
         LDA $AC8E,X     ; Item power B
         STA $AC8D,X     ; Replace A's
         LDA $9D8B,X     ; Item number B
         STA $9D8A,X     ; Replace A's
         LDA $E0         ; Item power A
         STA $AC8E,X     ; Replace B's
         LDA $E1         ; Item number A
         STA $9D8B,X     ; Replace B's
C3A1B7:  INX             ; List slot +1
         CPX $E7         ; End of list?
         BNE C3A192      ; Loop if not
         INY             ; Items done +1
         CPY $E7         ; Fully sorted?
         BNE C3A190      ; Loop if not
         PLB             ; Restore DB
         RTS

; Load item description for equipped relic (unused)
C3A1C3:  JSR C38308      ; Set desc ptrs
         JSR C393F2      ; Define Y
         LDA $4B         ; On "Relic 1"?
         BNE C3A1D2      ; Branch if not
         LDA $0023,Y     ; Relic 1
         BRA C3A1D5      ; Skip a line
C3A1D2:  LDA $0024,Y     ; Relic 2
C3A1D5:  JMP C35738      ; Load description

; Load item description for relic browsing
C3A1D8:  JSR C38308      ; Set desc ptrs
         TDC             ; Clear A
         LDA $4B         ; Gear list slot
         TAX             ; Index it
         LDA $7E9D8A,X   ; Inventory slot
         TAX             ; Index it
         LDA $1869,X     ; Item in slot
         JMP C35738      ; Load description

; Text pointers for party gear overview (SFC)
C3A1EA:  dw C3A21A       ; R-hand
         dw C3A21F       ; L-hand
         dw C3A225       ; Head
         dw C3A22B       ; Body
         dw C3A231       ; Relic 1
         dw C3A237       ; Relic 2
         dw C3A23D       ; R-hand
         dw C3A242       ; L-hand
         dw C3A248       ; Head
         dw C3A24E       ; Body
         dw C3A254       ; Relic 1
         dw C3A25A       ; Relic 2
         dw C3A260       ; R-hand
         dw C3A265       ; L-hand
         dw C3A26B       ; Head
         dw C3A271       ; Body
         dw C3A277       ; Relic 1
         dw C3A27D       ; Relic 2
         dw C3A283       ; R-hand
         dw C3A288       ; L-hand
         dw C3A28E       ; Head
         dw C3A294       ; Body
         dw C3A29A       ; Relic 1
         dw C3A2A0       ; Relic 2

; Positioned party gear overview text for member 1 (SFC)
C3A21A:  dw $394F : db $9F,$2D,$00     ; R-hand
C3A21F:  dw $396B : db $63,$3F,$A9,$00 ; L-hand
C3A225:  dw $39CF : db $8B,$7F,$9D,$00 ; Head
C3A22B:  dw $39EB : db $6B,$A7,$3F,$00 ; Body
C3A231:  dw $3A4F : db $8A,$6E,$54,$00 ; Relic 1
C3A237:  dw $3A6B : db $8A,$6E,$55,$00 ; Relic 2

; Positioned party gear overview text for member 2 (SFC)
C3A23D:  dw $3B4F : db $9F,$2D,$00     ; R-hand
C3A242:  dw $3B6B : db $63,$3F,$A9,$00 ; L-hand
C3A248:  dw $3BCF : db $8B,$7F,$9D,$00 ; Head
C3A24E:  dw $3BEB : db $6B,$A7,$3F,$00 ; Body
C3A254:  dw $3C4F : db $8A,$6E,$54,$00 ; Relic 1
C3A25A:  dw $3C6B : db $8A,$6E,$55,$00 ; Relic 2

; Positioned party gear overview text for member 3 (SFC)
C3A260:  dw $3D4F : db $9F,$2D,$00     ; R-hand
C3A265:  dw $3D6B : db $63,$3F,$A9,$00 ; L-hand
C3A26B:  dw $3DCF : db $8B,$7F,$9D,$00 ; Head
C3A271:  dw $3DEB : db $6B,$A7,$3F,$00 ; Body
C3A277:  dw $3E4F : db $8A,$6E,$54,$00 ; Relic 1
C3A27D:  dw $3E6B : db $8A,$6E,$55,$00 ; Relic 2

; Positioned party gear overview text for member 4 (SFC)
C3A283:  dw $3F4F : db $9F,$2D,$00     ; R-hand
C3A288:  dw $3F6B : db $63,$3F,$A9,$00 ; L-hand
C3A28E:  dw $3FCF : db $8B,$7F,$9D,$00 ; Head
C3A294:  dw $3FEB : db $6B,$A7,$3F,$00 ; Body
C3A29A:  dw $404F : db $8A,$6E,$54,$00 ; Relic 1
C3A2A0:  dw $406B : db $8A,$6E,$55,$00 ; Relic 2

; Text pointers for Equip menu
C3A2A6:  dw C3A31A       ; EQUIP
         dw C3A322       ; OPTIMUM
         dw C3A32C       ; RMOVE
         dw C3A334       ; EMPTY
C3A2AE:  dw C3A2CC       ; Head
         dw C3A2D3       ; Body

; Text pointers for Relic menu
C3A2B2:  dw C3A33C       ; EQUIP
         dw C3A344       ; REMOVE
C3A2B6:  dw C3A2DA       ; Relic
         dw C3A2E2       ; Relic

; Positioned text for Equip and Relic menus
C3A2BA:  dw $7A0D : db "R-hand",$00
C3A2C3:  dw $7A8D : db "L-hand",$00
C3A2CC:  dw $7B0D : db "Head",$00
C3A2D3:  dw $7B8D : db "Body",$00
C3A2DA:  dw $7B0D : db "Relic",$00
C3A2E2:  dw $7B8D : db "Relic",$00

; Positioned spaces for blanking options and title in gear menus
C3A2EA:  dw $790D : db "                            ",$00

; Positioned text for title in Equip and Relic menus
C3A309:  dw $7939 : db "EQUIP",$00
C3A311:  dw $7939 : db "REMOVE",$00

; Positioned text for options in Equip menu
C3A31A:  dw $790D : db "EQUIP",$00
C3A322:  dw $791B : db "OPTIMUM",$00
C3A32C:  dw $792D : db "RMOVE",$00
C3A334:  dw $793B : db "EMPTY",$00

; Positioned text for options in Relic menu
C3A33C:  dw $7911 : db "EQUIP",$00
C3A344:  dw $791F : db "REMOVE",$00

; Text pointers for Equip and Relic menus
C3A34D:  dw C3A371       ; Vigor
         dw C3A379       ; Stamina
         dw C3A383       ; Mag.Pwr
         dw C3A38D       ; Evade %
         dw C3A397       ; MBlock%
         dw C3A3A1       ; ->
         dw C3A3A5       ; ->
         dw C3A3A9       ; ->
         dw C3A3AD       ; ->
         dw C3A3B1       ; ->
         dw C3A3B5       ; ->
         dw C3A3B9       ; ->
         dw C3A3BD       ; ->
         dw C3A3C1       ; ->
C3A369:  dw C3A3C5       ; Speed
         dw C3A3CD       ; Bat.Pwr
         dw C3A3D7       ; Defense
         dw C3A3E1       ; Mag.Def

; Positioned text for Equip and Relic menus
C3A371:  dw $7CA9 : db "Vigor",$00
C3A379:  dw $7DA9 : db "Stamina",$00
C3A383:  dw $7E29 : db "Mag.Pwr",$00
C3A38D:  dw $7FA9 : db "Evade %",$00
C3A397:  dw $80A9 : db "MBlock%",$00
C3A3A1:  dw $7CBD : db ">",$00
C3A3A5:  dw $7D3D : db ">",$00
C3A3A9:  dw $7DBD : db ">",$00
C3A3AD:  dw $7E3D : db ">",$00
C3A3B1:  dw $7F3D : db ">",$00
C3A3B5:  dw $7FBD : db ">",$00
C3A3B9:  dw $7EBD : db ">",$00
C3A3BD:  dw $803D : db ">",$00
C3A3C1:  dw $80BD : db ">",$00
C3A3C5:  dw $7D29 : db "Speed",$00
C3A3CD:  dw $7EA9 : db "Bat.Pwr",$00
C3A3D7:  dw $7F29 : db "Defense",$00
C3A3E1:  dw $8029 : db "Mag.Def",$00
C3A3EB:  dw $7923 : db "Empty",$00
C3A3F3:  dw $7921 : db "Optimum",$00
C3A3FD:  dw $79A3 : db "Empty",$00
C3A405:  dw $79A1 : db "Optimum",$00
C3A40F:  dw $7A15 : db "Equipment changed.",$00

; Establish button purposes and autofire delays
C3A424:  LDA #$08        ; Initial delay
         STA $0229       ; For: General
         LDA #$03        ; Repeat delay
         STA $022A       ; For: General
         STA $0226       ; For: A in battle
         LDA #$20        ; Initial delay
         STA $0225       ; For: A in battle
         LDA $1D54       ; Game options
         AND #$40        ; Custom buttons?
         BEQ C3A441      ; Reset if not
         JSR C3A5C4      ; Apply user keys
         RTL             ; Exit
C3A441:  JSR C3A5D1      ; Reset buttons
         RTL

; Decode joypads for battle
C3A445:  LDA $1D54       ; Two players?
         BPL C3A458      ; Branch if not
         TDC             ; Clear A
         LDA $0201       ; Member slot
         TAX             ; Index it
         LDA $1D4F       ; Assigned pad
         AND.L C3A53D,X  ; Player 2's?
         BNE C3A45D      ; Branch if so
C3A458:  LDX $4218       ; Player 1 keys
         BRA C3A462      ; Skip 2 lines
C3A45D:  LDX $421A       ; Player 2 keys
         BRA C3A462      ; ...
C3A462:  JSR C3A483      ; Decode keys
         JSR C3A4BD      ; Do autofire
         JSR C3A4F6      ; Adjust it
         JMP C3A527      ; Restore $E0+

; Decode joypads for field menu
C3A46E:  LDX $4218       ; Player 1 keys
         JSR C3A483      ; Decode keys
         JSR C3A4BD      ; Do autofire
         JMP C3A527      ; Restore $E0+

; Decode joypads for field
C3A47A:  LDX $4218       ; Player 1 keys
         JSR C3A483      ; Decode keys
         JMP C3A527      ; Restore $E0+

; Update non-time-based joypad keys
C3A483:  LDY $E0         ; Temp var
         STY $0213       ; Make backup
         LDY $E7         ; Temp var
         STY $0215       ; Make backup
         LDY $E9         ; Temp var
         STY $0217       ; Make backup
         LDY $EB         ; Temp var
         STY $0219       ; Make backup
         STX $EB         ; Save pad keys
         REP #$20        ; 16-bit A
         LDA $0C         ; Former keys
         AND #$FFF0      ; Unused bits...
         STA $E0         ; Memorize them
         JSR C3A541      ; Convert keys
         LDA $0C         ; Former keys
         EOR #$FFFF      ; Invert them
         AND $06         ; Keep current
         STA $08         ; Set no-auto keys
         LDY $06         ; Pushed keys
         STY $0C         ; Set former keys
         LDA $4218       ; Player 1 keys
         ORA $421A       ; Add player 2's
         STA $04         ; Set merged keys
         SEP #$20        ; 8-bit A
         RTS

; Update slow autofire keys
C3A4BD:  REP #$20        ; 16-bit A
         LDA $06         ; Pushed keys
         AND #$FFF0      ; Clear pad type
         CMP $E0         ; Unchanged?
         SEP #$20        ; 8-bit A
         BNE C3A4E5      ; Use new if not
         LDA $0227       ; Initial delay
         BEQ C3A4D4      ; Branch if over
         DEC $0227       ; Initial delay -1
         BNE C3A4F1      ; No keys if > 0
C3A4D4:  DEC $0228       ; Repeat delay -1
         BNE C3A4F1      ; No keys if > 0
         LDA $022A       ; Delay: 3
         STA $0228       ; Set repeat timer
         LDY $06         ; Pushed keys
         STY $0A         ; Set slow keys
         BRA C3A4F5      ; Exit
C3A4E5:  LDA $0229       ; Delay: 8
         STA $0227       ; Set initial
         LDA $022A       ; Delay: 3
         STA $0228       ; Set repeat timer
C3A4F1:  LDY $08         ; No-autofire keys
         STY $0A         ; Set slow keys
C3A4F5:  RTS

; Adjust slow autofire keys for battle
C3A4F6:  LDA $06         ; Pushed keys
         BIT #$80        ; Pushing A?
         BEQ C3A517      ; Branch if not
         LDA $0225       ; Initial delay
         BEQ C3A506      ; Branch if over
         DEC $0225       ; Initial delay -1
         BNE C3A522      ; New keys if > 0
C3A506:  DEC $0226       ; Repeat delay -1
         BNE C3A522      ; New keys if > 0
         LDA $022A       ; Delay: 3
         STA $0226       ; Set repeat timer
         LDA #$80        ; Button: A
         TSB $0A         ; Add to slow keys
         BRA C3A526      ; Exit
C3A517:  LDA #$20        ; Delay: 32
         STA $0225       ; Set initial
         LDA $022A       ; Delay: 3
         STA $0226       ; Set repeat timer
C3A522:  LDA $08         ; No-autofire keys
         STA $0A         ; Set slow keys
C3A526:  RTS

; Restore backup of multipurpose variables
C3A527:  LDY $0213       ; $E0 backup
         STY $E0         ; Restore it
         LDY $0215       ; $E7 backup
         STY $E7         ; Restore it
         LDY $0217       ; $E9 backup
         STY $E9         ; Restore it
         LDY $0219       ; $EB backup
         STY $EB         ; Restore it
         TDC             ; Clear A
         RTL

; Bitfield for joypad assignments
C3A53D:  db $01          ; Member 1
         db $02          ; Member 2
         db $04          ; Member 3
         db $08          ; Member 4

; Convert pushed keys based on user settings (for SFC)
C3A541:  LDA $EB         ; Pushed keys
         AND #$0F00      ; Get D-Pad's
         STA $06         ; Set fast keys
         LDA #$0080      ; Target: A
         STA $E7         ; Set key #1
         LDA #$8000      ; Target: B
         STA $E9         ; Set key #2
         LDY $00         ; Cfg index: 0
         JSR C3A581      ; Do A and B
         LDA #$0040      ; Target: X
         STA $E7         ; Set key #1
         LDA #$4000      ; Target: Y
         STA $E9         ; Set key #2
         INY             ; Index +1
         JSR C3A581      ; Do X and Y
         LDA #$0020      ; Target: L
         STA $E7         ; Set key #1
         LDA #$0010      ; Target: R
         STA $E9         ; Set key #2
         INY             ; Index +1
         JSR C3A581      ; Do L and R
         LDA #$1000      ; Target: Start
         STA $E7         ; Set key #1
         LDA #$2000      ; Target: Select
         STA $E9         ; Set key #2
         INY             ; Index +1
         JMP C3A581      ; ...

; Convert two pushed keys to their respective purposes (for SFC)
C3A581:  LDA $EB         ; Pushed keys
         BIT $E7         ; Has key #1?
         BEQ C3A59B      ; Skip if not
         TDC             ; Clear A
         SEP #$20        ; 8-bit A
         LDA $0220,Y     ; Key actions
         AND #$F0        ; Get key #1's
         REP #$20        ; 16-bit A
         LSR A           ; Put in b3-b6
         LSR A           ; Put in b2-b5
         LSR A           ; Put in b1-b4
         TAX             ; Index it
         LDA.L C3A5B4,X  ; Action bit
         TSB $06         ; Set fast key
C3A59B:  LDA $EB         ; Pushed keys
         BIT $E9         ; Has key #2?
         BEQ C3A5B3      ; Exit if not
         TDC             ; Clear A
         SEP #$20        ; 8-bit A
         LDA $0220,Y     ; Key actions
         AND #$0F        ; Get key #2's
         REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C3A5B4,X  ; Action bit
         TSB $06         ; Set fast key
C3A5B3:  RTS

; Bitfield for button purposes
C3A5B4:  dw $1000        ; End        (Start)
         dw $0080        ; Confirm    (A)
         dw $8000        ; Cancel     (B)
         dw $0040        ; Menu       (X)
         dw $4000        ; Switch     (Y)
         dw $0020        ; Page up    (L)
         dw $0010        ; Page down  (R, Select)
         dw $2000        ; Unused

; Apply player's button settings (SFC)
C3A5C4:  LDY $1D50       ; A, B, X, Y
         STY $0220       ; Set purposes
         LDY $1D52       ; L, R, Select
         STY $0222       ; Set purposes
         RTS

; Apply default button settings
C3A5D1:  LDY #$3412      ; A, B, X, Y
         STY $0220       ; Set purposes
         LDY #$0656      ; L, R, Select
         STY $0222       ; Set purposes
         RTS

; Clear buffer for storing actor's pseudonym in ending
C3A5DE:  TDC             ; Clear A
         TAX             ; Index: 0
         REP #$20        ; 16-bit A
C3A5E2:  STA $7EA271,X   ; Tile row A
         INX             ; Index +1
         INX             ; Index +1
         STA $7EA271,X   ; Tile row B
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0240      ; Done 36 tiles?
         BNE C3A5E2      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Upload element's VWF graphics; freeze CGRAM
C3A5F6:  JSR C3A600      ; Set src and dst
         LDA #$01        ; CGRAM: Freeze
         TRB $45         ; Set NMI flag
         JMP C314AC      ; Upload graphics

; Set to upload VWF string graphics (elements, ending pseudonym)
C3A600:  STY $1B         ; Set VRAM ptr
         LDY #$A271      ; 7E/A271
         STY $1D         ; Set src LBs
         LDY #$0120      ; Bytes: 288
         STY $19         ; Set data size
         LDA #$7E        ; Bank: 7E
         STA $1F         ; Set src HB
         RTS

; Build tilemap for actor's pseudonym in ending
C3A611:  LDX #$7849      ; Base: 7E/7849
         STX $EB         ; Set map ptr LBs
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set ptr HB
         LDY #$0598      ; Ends at 12,23
         STY $E7         ; Set row's limit
         LDY #$0580      ; Starts at 1,23
         LDX #$2410      ; Tile 16, pal 1
         STX $E0         ; Priority enabled
         JSR C3A783      ; Build row 1
         LDY #$05D8      ; Ends at 12,24
         STY $E7         ; Set row's limit
         LDY #$05C0      ; Starts at 1,24
         LDX #$2411      ; Tile 17, pal 1
         STX $E0         ; Priority enabled
         JSR C3A783      ; Build row 2
         RTS

; Load and set to upload VWF graphics for actor's pseudonym
C3A63B:  JSR C3A5DE      ; Clear GFX buffer
         STZ $8D         ; String width: 0
         STZ $ED         ; VRAM index LB: 0
         STZ $EE         ; VRAM index HB: 0
         LDA #$06        ; Letters: 6
         STA $F1         ; Set counter
         LDX $00         ; Letter index: 0
C3A64A:  LDA $7E9E89,X   ; Letter
         JSR C3A8A9      ; Adjust value
         PHX             ; Save char index
         JSR C3A8B1      ; Load graphics
         PLX             ; Letter index
         INX             ; Letter index +1
         DEC $F1         ; One less letter
         BNE C3A64A      ; Loop till last
         LDY #$2080      ; VRAM pointer
         JSR C3A600      ; Queue upload
         RTS

; Build description tilemap for Skills submenus
C3A662:  LDX #$8049      ; Base: 7E/8049
         STX $EB         ; Set map ptr LBs
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set ptr HB
         LDY #$00BC      ; Ends at 30,3
         STY $E7         ; Set row's limit
         LDY #$0084      ; Starts at 3,3
         LDX #$3500      ; Tile 256, pal 5
         STX $E0         ; Priority enabled
         JSR C3A783      ; Do line 1, row 1
         LDY #$00FC      ; Ends at 30,4
         STY $E7         ; Set row's limit
         LDY #$00C4      ; Starts at 3,4
         LDX #$3501      ; Tile 257, pal 5
         STX $E0         ; Priority enabled
         JSR C3A783      ; Do line 1, row 2
         LDY #$013C      ; Ends at 30,5
         STY $E7         ; Set row's limit
         LDY #$0104      ; Starts at 3,5
         LDX #$3538      ; Tile 312, pal 5
         STX $E0         ; Priority enabled
         JSR C3A783      ; Do line 2, row 1
         LDY #$017C      ; Ends at 30,6
         STY $E7         ; Set row's limit
         LDY #$0144      ; Starts at 3,6
         LDX #$3539      ; Tile 313, pal 5
         STX $E0         ; Priority enabled
         JMP C3A783      ; Do line 2, row 2

; Build description tilemap for Relic menu
C3A6AB:  LDX #$7849      ; Base: 7E/7849
         STX $EB         ; Set map ptr LBs
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set ptr HB
         LDY #$01BC      ; Ends at 30,7
         STY $E7         ; Set row's limit
         LDY #$0184      ; Starts at 3,7
         LDX #$3500      ; Tile 256, pal 5
         STX $E0         ; Priority enabled
         JSR C3A783      ; Do line 1, row 1
         LDY #$01FC      ; Ends at 30,8
         STY $E7         ; Set row's limit
         LDY #$01C4      ; Starts at 3,8
         LDX #$3501      ; Tile 257, pal 5
         STX $E0         ; Priority enabled
         JSR C3A783      ; Do line 1, row 2
         LDY #$023C      ; Ends at 30,9
         STY $E7         ; Set row's limit
         LDY #$0204      ; Starts at 3,9
         LDX #$3538      ; Tile 312, pal 5
         STX $E0         ; Priority enabled
         JSR C3A783      ; Do line 2, row 1
         LDY #$027C      ; Ends at 30,10
         STY $E7         ; Set row's limit
         LDY #$0244      ; Starts at 3,10
         LDX #$3539      ; Tile 313, pal 5
         STX $E0         ; Priority enabled
         JMP C3A783      ; Do line 2, row 2

; Build description tilemap for shop menu
C3A6F4:  LDX #$7849      ; Base: 7E/7849
         STX $EB         ; Set map ptr LBs
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set ptr HB
         LDY #$04BC      ; Ends at 30,19
         STY $E7         ; Set row's limit
         LDY #$0484      ; Starts at 3,19
         LDX #$3500      ; Tile 256, pal 5
         STX $E0         ; Priority enabled
         JSR C3A783      ; Do line 1, row 1
         LDY #$04FC      ; Ends at 30,20
         STY $E7         ; Set row's limit
         LDY #$04C4      ; Starts at 3,20
         LDX #$3501      ; Tile 257, pal 5
         STX $E0         ; Priority enabled
         JSR C3A783      ; Do line 1, row 2
         LDY #$053C      ; Ends at 30,21
         STY $E7         ; Set row's limit
         LDY #$0504      ; Starts at 3,21
         LDX #$3538      ; Tile 312, pal 5
         STX $E0         ; Priority enabled
         JSR C3A783      ; Do line 2, row 1
         LDY #$057C      ; Ends at 30,22
         STY $E7         ; Set row's limit
         LDY #$0544      ; Starts at 3,22
         LDX #$3539      ; Tile 313, pal 5
         STX $E0         ; Priority enabled
         JMP C3A783      ; Do line 2, row 2

; Build description tilemap for Item or Colosseum menu
C3A73D:  LDX #$7849      ; Base: 7E/7849
         STX $EB         ; Set map ptr LBs
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set ptr HB
         LDY #$01BC      ; Ends at 30,7
         STY $E7         ; Set row's limit
         LDY #$0184      ; Starts at 3,7
         LDX #$3500      ; Tile 256, pal 5
         STX $E0         ; Priority enabled
         JSR C3A783      ; Do line 1, row 1
         LDY #$01FC      ; Ends at 30,8
         STY $E7         ; Set row's limit
         LDY #$01C4      ; Starts at 3,8
         LDX #$3501      ; Tile 257, pal 5
         STX $E0         ; Priority enabled
         JSR C3A783      ; Do line 1, row 2
         LDY #$023C      ; Ends at 30,9
         STY $E7         ; Set row's limit
         LDY #$0204      ; Starts at 3,9
         LDX #$3538      ; Tile 312, pal 5
         STX $E0         ; Priority enabled
         JSR C3A783      ; Do line 2, row 1
         LDY #$027C      ; Ends at 30,10
         STY $E7         ; Set row's limit
         LDY #$0244      ; Starts at 3,10
         LDX #$3539      ; Tile 313, pal 5
         STX $E0         ; Priority enabled
C3A783:  REP #$20        ; 16-bit A
C3A785:  LDA $E0         ; Tile attributes
         STA [$EB],Y     ; Put in tilemap
         INC $E0         ; Tile +1
         INC $E0         ; Tile +1
         INY             ; Index +1
         INY             ; Index +1
         CPY $E7         ; Beyond range?
         BNE C3A785      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Clear buffer for VWF description graphics
C3A796:  PHB             ; Save DB
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         TDC             ; Clear A
         TAX             ; Tile index: 0
         REP #$20        ; 16-bit A
C3A79F:  STZ $A271,X     ; Tile A, row 1
         STZ $A273,X     ; Tile A, row 2
         STZ $A275,X     ; Tile A, row 3
         STZ $A277,X     ; Tile A, row 4
         STZ $A279,X     ; Tile A, row 5
         STZ $A27B,X     ; Tile A, row 6
         STZ $A27D,X     ; Tile A, row 7
         STZ $A27F,X     ; Tile A, row 8
         STZ $A281,X     ; Tile B, row 1
         STZ $A283,X     ; Tile B, row 2
         STZ $A285,X     ; Tile B, row 3
         STZ $A287,X     ; Tile B, row 4
         STZ $A289,X     ; Tile B, row 5
         STZ $A28B,X     ; Tile B, row 6
         STZ $A28D,X     ; Tile B, row 7
         STZ $A28F,X     ; Tile B, row 8
         STZ $A291,X     ; Tile C, row 1
         STZ $A293,X     ; Tile C, row 2
         STZ $A295,X     ; Tile C, row 3
         STZ $A297,X     ; Tile C, row 4
         STZ $A299,X     ; Tile C, row 5
         STZ $A29B,X     ; Tile C, row 6
         STZ $A29D,X     ; Tile C, row 7
         STZ $A29F,X     ; Tile C, row 8
         STZ $A2A1,X     ; Tile D, row 1
         STZ $A2A3,X     ; Tile D, row 2
         STZ $A2A5,X     ; Tile D, row 3
         STZ $A2A7,X     ; Tile D, row 4
         STZ $A2A9,X     ; Tile D, row 5
         STZ $A2AB,X     ; Tile D, row 6
         STZ $A2AD,X     ; Tile D, row 7
         STZ $A2AF,X     ; Tile D, row 8
         TXA             ; Tile index
         CLC             ; Prepare ADC
         ADC #$0040      ; Skip 4 tiles
         TAX             ; Reindex it
         CPX #$0700      ; Done 112 tiles?
         BNE C3A79F      ; Loop if not
         SEP #$20        ; 8-bit A
         PLB             ; Restore DB
         RTS

; Update VWF description
C3A80E:  TAX             ; Index mode
         JMP (C3A812,X)  ; Handle mode

; Jump table for the above
C3A812:  dw C3A818       ; Clear description
         dw C3A82F       ; Sustain description
         dw C3A81B       ; Initialize variables

; Mode 0: Clear description
C3A818:  JSR C3A796      ; Clear desc GFX

; Mode 2: Initialize variables
C3A81B:  STZ $8D         ; Line width: 0
         LDX $2D         ; Queue index
         LDA #$01        ; Mode: 1
         STA $3649,X     ; Next: Update
         TDC             ; Clear A
         REP #$20        ; 16-bit A
         STA $33CA,X     ; Char index: 0
         STA $344A,X     ; VRAM index: 0
         SEP #$20        ; 8-bit A

; Mode 1: Sustain description
C3A82F:  LDA $26         ; Menu mode
         CMP #$17        ; Item menu top?
         BEQ C3A88D      ; Blank if so
         LDA $46         ; Menu flags
         AND #$C0        ; No scrollbar?
         BEQ C3A841      ; Branch if so
         LDA $06         ; Pushed keys
         AND #$30        ; Using L or R?
         BNE C3A895      ; Reset if so
C3A841:  LDA $45         ; Menu flags
         BIT #$20        ; Ignore D-Pad?
         BNE C3A84D      ; Branch if so
         LDA $07         ; Pushed keys
         AND #$0F        ; Using D-Pad?
         BNE C3A895      ; Reset if so
C3A84D:  LDA $45         ; Menu flags
         BIT #$10        ; Clear desc?
         BNE C3A895      ; Reset if so
         LDY $2D         ; Queue index
         LDX $344A,Y     ; VRAM index
         STX $ED         ; Memorize it
         LDX $33CA,Y     ; Char index

; Fork: Handle line break
C3A85D:  LDA $7E9EC9,X   ; Text character
         BEQ C3A89C      ; Branch if <end>
         CMP #$01        ; Line break?
         BNE C3A875      ; Branch if not
         STZ $8D         ; Line width: 0
         REP #$20        ; 16-bit A
         LDA #$0380      ; Base tile: 57
         STA $344A,Y     ; Set VRAM index
         SEP #$20        ; 8-bit A
         BRA C3A87D      ; Queue upload

; Fork: Handle character
C3A875:  JSR C3A8A9      ; Char number -128
         PHX             ; Save char index
         JSR C3A8B1      ; Load graphics
         PLX             ; Char index

; Fork: Queue upload, advance char index
C3A87D:  INX             ; Char index +1
         LDY $2D         ; Queue index
         REP #$20        ; 16-bit A
         TXA             ; Char index
         STA $33CA,Y     ; Put in queue
         SEP #$20        ; 8-bit A
         JSR C3A991      ; Queue upload
         SEC             ; Set to requeue
         RTS

; Fork: Clear description, stop updating
C3A88D:  JSR C3A796      ; Clear desc GFX
         JSR C3A991      ; Set to upload
         CLC             ; Set to dequeue
         RTS

; Fork: Set to reset description
C3A895:  LDX $2D         ; Queue index
         STZ $3649,X     ; Mode: 0
         SEC             ; Set to requeue
         RTS

; Fork: Handle terminator
C3A89C:  LDA #$01        ; CGRAM: Refresh
         TSB $45         ; Set NMI flag
         LDX $2D         ; Queue index
         LDA #$02        ; Mode: 2
         STA $3649,X     ; Next: Init
         SEC             ; Set to requeue
         RTS

; Make character number zero-based, clear graphics table pointer
C3A8A9:  SEC             ; Prepare SBC
         SBC #$80        ; Adjust letter
         STZ $EB         ; Table ptr LB: 0
         STZ $EC         ; Table ptr HB: 0
         RTS

; Load VWF character's graphics into string, add shadow effect
C3A8B1:  PHA             ; Save text char
         STA $004202     ; Set multiplicand
         LDA #$16        ; GFX data size
         STA $004203     ; Set multiplier
         LDA #$0B        ; Rows left: 11
         STA $E5         ; Set counter
         REP #$20        ; 16-bit A
         LDA $004216     ; Char index
         CLC             ; Prepare ADC
         ADC $EB         ; For SFC...
         TAY             ; Set ROM index
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $8D         ; Textline width
         AND #$F8        ; Drop WIP tile's
         REP #$20        ; 16-bit A
         ASL A           ; x2
         ASL A           ; x4
         CLC             ; Prepare ADC
         ADC $ED         ; Add VRAM index
         TAX             ; Set RAM index

; Fork: Load 1bpp row graphics, shift to fit string
C3A8D9:  PHX             ; Save RAM index
         REP #$20        ; 16-bit A
         TYX             ; ROM index
         LDA $C490C0,X   ; 12-px row GFX
         STZ $E7         ; Blank slice C
         STZ $E9         ; Clear byte 4
         STA $E8         ; Set slices A+B
         JSR C3A94F      ; Shift pixels

; Fork: Insert row segment C, copy as shadow below (2bpp)
C3A8EA:  PLX             ; RAM index
         LDA $E7         ; Slices B and C
         SEP #$20        ; 8-bit A
         ORA $7EA2B9,X   ; Add WIP plane A
         STA $7EA2B9,X   ; Set WIP plane A
         REP #$20        ; 16-bit A
         LSR A           ; Shift 1 px right
         SEP #$20        ; 8-bit A
         ORA $7EA2BC,X   ; Add WIP plane B
         STA $7EA2BC,X   ; Set WIP plane B

; Fork: Insert row segment B, copy as shadow below (2bpp)
C3A904:  REP #$20        ; 16-bit A
         LDA $E8         ; Slices A and B
         SEP #$20        ; 8-bit A
         ORA $7EA299,X   ; Add WIP plane A
         STA $7EA299,X   ; Set WIP plane A
         REP #$20        ; 16-bit A
         LSR A           ; Shift 1 px right
         SEP #$20        ; 8-bit A
         ORA $7EA29C,X   ; Add WIP plane B
         STA $7EA29C,X   ; Set WIP plane B

; Fork: Insert row segment A, copy as shadow below (2bpp)
C3A91F:  REP #$20        ; 16-bit A
         LDA $E8         ; Slices A and B
         SEP #$20        ; 8-bit A
         XBA             ; Get slice A
         ORA $7EA279,X   ; Add WIP plane A
         STA $7EA279,X   ; Set WIP plane A
         LSR A           ; Shift 1 px right
         ORA $7EA27C,X   ; Add WIP plane B
         STA $7EA27C,X   ; Set WIP plane B

; Fork: Handle next row
C3A937:  INX             ; RAM index +1
         INX             ; RAM index +1
         INY             ; ROM index +1
         INY             ; ROM index +1
         DEC $E5         ; One less row
         BNE C3A8D9      ; Loop till last

; Fork: Add character's width to line total
C3A93F:  TDC             ; Clear A
         PLA             ; Text character
         CLC             ; Prepare ADC
         ADC #$20        ; Use field format
         TAX             ; Index it
         LDA $8D         ; Line width
         CLC             ; Prepare ADC
         ADC $C48FC0,X   ; Add char width
         STA $8D         ; Save changes
         RTS

; Shift VWF character's row for string insertion
C3A94F:  SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $8D         ; Line width
         AND #$07        ; WIP tile's
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         JMP (C3A95D,X)  ; Shift row

; Jump table for the above
C3A95D:  dw C3A96F       ; 0: 4 px left
         dw C3A973       ; 1: 3 px left
         dw C3A977       ; 2: 2 px left
         dw C3A97B       ; 3: 1 px left
         dw C3A97F       ; 4: Unchanged
         dw C3A98C       ; 5: 1 px right
         dw C3A988       ; 6: 2 px right
         dw C3A984       ; 7: 3 px right
         dw C3A980       ; 8: 4 px right (unused)

; Shift VWF character's row left for string insertion
C3A96F:  ASL $E7         ; Do slice B+C
         ROL $E9         ; Do slice A
C3A973:  ASL $E7         ; Do slice B+C
         ROL $E9         ; Do slice A
C3A977:  ASL $E7         ; Do slice B+C
         ROL $E9         ; Do slice A
C3A97B:  ASL $E7         ; Do slice B+C
         ROL $E9         ; Do slice A
C3A97F:  RTS

; Shift VWF character's row right for string insertion
C3A980:  LSR $E9         ; Do slice A
         ROR $E7         ; Do slice B+C
C3A984:  LSR $E9         ; Do slice A
         ROR $E7         ; Do slice B+C
C3A988:  LSR $E9         ; Do slice A
         ROR $E7         ; Do slice B+C
C3A98C:  LSR $E9         ; Do slice A
         ROR $E7         ; Do slice B+C
         RTS

; Set to upload VWF description, freeze CGRAM
C3A991:  LDY #$6800      ; $D000
         STY $1B         ; Set VRAM ptr
         LDY #$A271      ; 7E/A271
         STY $1D         ; Set src LBs
         LDY #$0700      ; Bytes: 1792
         STY $19         ; Set data size
         LDA #$7E        ; Bank: 7E
         STA $1F         ; Set src HB
         LDA #$01        ; CGRAM: Freeze
         TRB $45         ; Set NMI flag
         RTS

; Load and upload VWF graphics for all elements
C3A9A9:  LDX $00         ; Elem index: 0
C3A9AB:  LDA $D8E90E,X   ; Elem text char
         STA $7E9EC9,X   ; Memorize it
         INX             ; Elem index +1
         CPX #$0009      ; Terminator?
         BNE C3A9AB      ; Loop if not
         LDY #$6C00      ; $D800
         STY $F1         ; Set VRAM ptr
         TDC             ; Clear A
         TAX             ; Elem index: 0
C3A9C0:  LDA $7E9EC9,X   ; Elem text char
         BEQ C3A9E2      ; Exit if none
         JSR C3A8A9      ; Adjust value
         PHX             ; Save index
         JSR C3A9E5      ; Load graphics
         PLX             ; Elem index
         INX             ; Elem index +1
         LDY $F1         ; VRAM pointer
         JSR C3A5F6      ; Upload graphics
         REP #$20        ; 16-bit A
         LDA $F1         ; VRAM pointer
         CLC             ; Prepare ADC
         ADC #$0020      ; Skip 4 tiles
         STA $F1         ; Save changes
         SEP #$20        ; 8-bit A
         BRA C3A9C0      ; Do next element
C3A9E2:  JMP C30F89      ; Dequeue upload

; Load element's graphics (VWF)
C3A9E5:  PHA             ; Save text char
         LDY #$0040      ; Bytes: 64
         STY $F3         ; Set buffer size
         JSR C3B437      ; Clear GFX buffer
         STZ $8D         ; String width: 0
         STZ $ED         ; VRAM index LB: 0
         STZ $EE         ; VRAM index HB: 0
         PLA             ; Elem text char
         JMP C3A8B1      ; Load graphics

; 73: Initialize final battle lineup
C3A9F8:  JSR C3352F      ; Reset/Stop stuff
         JSR C36904      ; Reset BGs' X/Y
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         JSR C3AC54      ; Load navig data
         JSR C3AC5D      ; Relocate cursor
         JSR C307B0      ; Queue cursor OAM
         JSR C3AAEE      ; Clear candidates
         JSR C3AAFD      ; Reset user's list
         JSR C3AB13      ; Draw menu
         JSR C39497      ; Set to shift text
         LDA #$74        ; C3/AA25
         STA $27         ; Queue: Sustain menu
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         JSR C30EFD      ; Queue text upload
         JMP C33541      ; BRT:1 + NMI

; 74: Sustain final battle lineup
C3AA25:  JSR C3AB89      ; Redraw candidates
         JSR C3ABB4      ; Redraw user's list
         JSR C3AC5A      ; Handle D-Pad
         JSR C30EFD      ; Queue text upload

; Fork: Handle B
C3AA31:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C3AA63      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         LDA $4A         ; R-List's empty?
         BEQ C3AAA6      ; Exit if so
         DEC $4A         ; R-List size -1
         TDC             ; Clear A
         LDA $4A         ; R-List size
         TAX             ; Index it
         LDA $0205,X     ; Last R-List char
         PHA             ; Save this actor
         LDA #$FF        ; Actor: None
         STA $0205,X     ; Clear R-List slot
         LDX $00         ; L-List slot: 1
         PLA             ; Removed actor
C3AA50:  CMP $7E9D8A,X   ; In L-List slot?
         BEQ C3AA5C      ; Enable it if so
         INX             ; L-List slot +1
         CPX #$000C      ; Done all 12?
         BNE C3AA50      ; Loop if not
C3AA5C:  LDA #$20        ; Color: User's
         STA $7EAA8D,X   ; Set L-List name's
         RTS

; Fork: Handle actor selection
C3AA63:  LDA $09         ; No-autofire keys
         BIT #$10        ; Pushing Start?
         BNE C3AA99      ; Branch if so
         LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C3AAA6      ; Exit if not
         JSR C30EB2      ; Sound: Click
         TDC             ; Clear A
         LDA $4B         ; On Reset?
         BEQ C3AAA7      ; Branch if so
         CMP #$0D        ; On "End"?
         BEQ C3AA99      ; Branch if so
         TAX             ; Clicked slot
         LDA $7E9D89,X   ; Nobody there?
         BMI C3AAA6      ; Exit if so
         TDC             ; ...
         LDA $4B         ; Clicked slot
         DEC A           ; Now 0-12
         TAX             ; Index it
         LDA $7EAA8D,X   ; Name color
         CMP #$20        ; Player's?
         BNE C3AAA6      ; Exit if not
         JSR C3AAB2      ; Add chosen char
         LDA $4A         ; Selection count
         CMP #$0C        ; Added 12 actors?
         BEQ C3AAAD      ; Go to End if so
         RTS

; Fork: Handle "End"
C3AA99:  JSR C30EB2      ; Sound: Click
         JSR C3AACA      ; Auto-fill list
         LDA #$FF        ; Null value
         STA $27         ; Queue menu exit
         STZ $26         ; Next: Fade-out
         RTS             ; ...
C3AAA6:  RTS

; Fork: Handle "Reset"
C3AAA7:  JSR C3AAFD      ; Reset user's list
         INC $4E         ; Move cursor down
         RTS

; Fork: Put cursor on "End"
C3AAAD:  LDA #$0D        ; Row: 14th
         STA $4E         ; Set cursor's
         RTS

; Add chosen actor to player's list for final battle
C3AAB2:  TDC             ; ...
         LDA $4A         ; Slot to fill
         TAY             ; Index it
         LDA $4B         ; Clicked slot
         TAX             ; Index it
         LDA #$28        ; Color: Gray
         STA $7EAA8C,X   ; Set L-Name's
         LDA $7E9D89,X   ; Chosen actor
         TYX             ; ...
         STA $0205,X     ; To user's list
         INC $4A         ; R-List size +1
         RTS

; Complete player's actor list for final battle
C3AACA:  LDA $4A         ; R-List size
         CMP #$0C        ; 12 actors?
         BEQ C3AAED      ; Exit if so
         TDC             ; Clear A
         TAX             ; L-List slot: 1
C3AAD2:  LDA $7EAA8D,X   ; Name color
         CMP #$20        ; Player's?
         BNE C3AAE7      ; Skip if not
         TDC             ; ...
         LDA $4A         ; R-List slot
         TAY             ; Index it
         LDA $7E9D8A,X   ; L-List actor
         STA $0205,Y     ; Add to list
         INC $4A         ; R-List slot +1
C3AAE7:  INX             ; L-List slot +1
         CPX #$000C      ; Done all 12?
         BNE C3AAD2      ; Loop if not
C3AAED:  RTS

; Clear candidate list for final battle (four unused slots)
C3AAEE:  TDC             ; Clear A
         TAX             ; List slot: 1
C3AAF0:  LDA #$FF        ; Actor: None
         STA $7E9D89,X   ; Clear slot
         INX             ; List slot +1
         CPX #$0010      ; Done 16?...
         BNE C3AAF0      ; Loop if not
         RTS

; Reset player's actor list for final battle
C3AAFD:  TDC             ; Clear A
         TAX             ; List slot: 1
C3AAFF:  LDA #$FF        ; Actor: None
         STA $0205,X     ; Put in slot
         LDA #$20        ; Color: User's
         STA $7EAA8D,X   ; Set name color
         INX             ; List slot +1
         CPX #$000C      ; Done all 12?
         BNE C3AAFF      ; Loop if not
         STZ $4A         ; List size: 0
         RTS

; Draw menu for final battle
C3AB13:  LDA #$02        ; 32x64 at $0000
         STA $2107       ; Set BG1 map loc
         LDY #C3AB49     ; C3/AB49
         JSR C30341      ; Draw window
         JSR C30E52      ; Upload window
         JSR C36A3C      ; Clear BG3 map A
         JSR C30E6E      ; Upload BG3 A+B
         JSR C36A15      ; Clear BG1 map A
         JSR C36A19      ; Clear BG1 map B
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDX #C3AC84     ; Text ptrs loc
         LDY #$0006      ; Strings: 3
         JSR C369BA      ; Draw End, etc.
         JSR C3AC19      ; Draw numbers
         JSR C3AB4D      ; List candidates
         JSR C3AB89      ; Draw candidates
         JSR C30E28      ; Upload text
         JMP C30E36      ; Upload BG1c...

; Window layout for final battle lineup
C3AB49:  dw $588B,$181C  ; 30x26 at $588B

; Compile candidates for final battle
C3AB4D:  STZ $E6         ; List slot: 1
         TDC             ; Clear A
         TAX             ; 1st: Terra
C3AB51:  PHX             ; Save actor
         LDA $1850,X     ; Party info
         AND #$40        ; Object's off?
         BEQ C3AB81      ; Skip if so
         LDA $1850,X     ; Party info
         AND #$07        ; In a party?
         BEQ C3AB81      ; Skip if not
         STX $E7         ; Save actor
         REP #$20        ; 16-bit A
         TXA             ; Actor slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C36969,X  ; Actor address
         TAY             ; Index it
         SEP #$20        ; 8-bit A
         LDA $0000,Y     ; Actor in slot
         CMP #$0E        ; Guest?
         BCS C3AB81      ; Skip if so
         TDC             ; Clear A
         LDA $E6         ; List slot
         TAX             ; Index it
         LDA $E7         ; Actor slot
         STA $7E9D8A,X   ; Add to list
         INC $E6         ; List slot +1
C3AB81:  PLX             ; Actor slot
         INX             ; Actor slot +1
         CPX #$0010      ; Done all 16?
         BNE C3AB51      ; Loop if not
         RTS

; Draw list of candidates for final battle
C3AB89:  LDY #$3A15      ; Tilemap ptr
         STY $F5         ; Set position
         TDC             ; Clear A
         TAX             ; List slot: 1
C3AB90:  JSR C3ABDC      ; Set pos, WRAM
         PHX             ; Save list slot
         TDC             ; Clear A
         LDA $7EAA8D,X   ; Name palette
         STA $29         ; Set attributes
         LDA $7E9D8A,X   ; Actor in slot
         BMI C3ABA6      ; Blank if none
         JSR C3ABF0      ; Draw name
         BRA C3ABA9      ; Skip a line
C3ABA6:  JSR C3AC0B      ; Blank slot
C3ABA9:  JSR C3ABFE      ; VRAM row +2
         PLX             ; List slot
         INX             ; List slot +1
         CPX #$000C      ; Done all 12?
         BNE C3AB90      ; Loop if not
         RTS

; Draw player's actor list for final battle
C3ABB4:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         LDY #$3A31      ; Tilemap ptr
         STY $F5         ; Set position
         TDC             ; Clear A
         TAX             ; List slot: 1
C3ABBF:  JSR C3ABDC      ; Set pos, WRAM
         PHX             ; Save list slot
         TDC             ; Clear A
         LDA $0205,X     ; Actor in slot
         BMI C3ABCE      ; Blank if none
         JSR C3ABF0      ; Draw name
         BRA C3ABD1      ; Skip a line
C3ABCE:  JSR C3AC0B      ; Blank slot
C3ABD1:  JSR C3ABFE      ; VRAM row +2
         PLX             ; List slot
         INX             ; List slot +1
         CPX #$000C      ; Done all 12?
         BNE C3ABBF      ; Loop if not
         RTS

; Prepare actor name drawing for final battle lineup
C3ABDC:  LDY #$9E89      ; 7E/9E89
         STY $2181       ; Set WRAM LBs
         REP #$20        ; 16-bit A
         LDA $F5         ; Tilemap ptr
         SEP #$20        ; 8-bit A
         STA $2180       ; Set position LB
         XBA             ; Switch to HB
         STA $2180       ; Set position HB
         RTS

; Draw actor's name for final battle lineup
C3ABF0:  ASL A           ; Actor x2
         REP #$20        ; 16-bit A
         TAX             ; Index it
         LDA.L C36969,X  ; Actor address
         TAY             ; Index it
         SEP #$20        ; 8-bit A
         JMP C334D2      ; Draw name

; Point two rows down in tilemap
C3ABFE:  REP #$20        ; 16-bit A
         LDA $F5         ; Tilemap ptr
         CLC             ; Prepare ADC
         ADC #$0080      ; +2 rows down
         STA $F5         ; Save changes
         SEP #$20        ; 8-bit A
         RTS

; Blank actor name slot
C3AC0B:  LDX #$0006      ; Spaces: 6
         LDA #$FF        ; Space char
C3AC10:  STA $2180       ; Add to string
         DEX             ; One less left
         BNE C3AC10      ; Loop till last
         JMP C37FD9      ; Draw 6 spaces

; Draw both lists of numbers for final battle lineup
C3AC19:  LDA #$01        ; Number: "1"
         STA $E6         ; Set as current
         LDY #$3A0F      ; Tilemap ptr
         STY $F5         ; Set position
         LDX #$000C      ; Numbers: 12
         STX $F1         ; Set counter
         JSR C3AC3B      ; Draw left list
         LDA #$01        ; Number: "1"
         STA $E6         ; Set as current
         LDY #$3A2B      ; Tilemap ptr
         STY $F5         ; Set position
         LDX #$000C      ; Numbers: 12
         STX $F1         ; Set counter
         JMP C3AC3B      ; Draw right list

; Draw current list of numbers for final battle lineup
C3AC3B:  TDC             ; Clear A
         TAX             ; Numbers done: 0
C3AC3D:  PHX             ; Save counter
         LDA $E6         ; Current number
         JSR C304E0      ; Turn into text
         LDX $F5         ; Text position
         JSR C304B6      ; Draw 2 digits
         INC $E6         ; Number +1
         JSR C3ABFE      ; VRAM row +2
         PLX             ; Numbers done
         INX             ; Numbers done +1
         CPX $F1         ; Done all 12?
         BNE C3AC3D      ; Loop if not
         RTS

; Load navigation data for final battle lineup
C3AC54:  LDY #C3AC63     ; C3/AC63
         JMP C305FE      ; Load navig data

; Handle D-Pad for final battle lineup
C3AC5A:  JSR C3072D      ; Handle D-Pad
C3AC5D:  LDY #C3AC68     ; C3/AC68
         JMP C30640      ; Relocate cursor

; Navigation data for final battle lineup
C3AC63:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $0E          ; 14 rows

; Cursor positions for final battle lineup
C3AC68:  dw $2010        ; Reset
         dw $2C20        ; Actor 1
         dw $3820        ; Actor 2
         dw $4420        ; Actor 3
         dw $5020        ; Actor 4
         dw $5C20        ; Actor 5
         dw $6820        ; Actor 6
         dw $7420        ; Actor 7
         dw $8020        ; Actor 8
         dw $8C20        ; Actor 9
         dw $9820        ; Actor 10
         dw $A420        ; Actor 11
         dw $B020        ; Actor 12
         dw $BC10        ; End

; Text pointers for final battle lineup
C3AC84:  dw C3AC8A       ; End
         dw C3AC90       ; Reset
         dw C3AC98       ; Determine order

; Positioned text for final battle lineup
C3AC8A:  dw $4011 : db "End",$00
C3AC90:  dw $3991 : db "Reset",$00
C3AC98:  dw $391D : db "Determine order",$00

; 71: Initialize Colosseum item menu
C3ACAA:  STZ $0201       ; Face Shadow: No
         LDA $0205       ; Empty item...
         JSR C39D5E      ; Add to stock...
         JSR C31AE2      ; Init list vars
         JSR C37D25      ; Relocate cursor
         JSR C3AD27      ; Draw/Upload menu
         TDC             ; Gradient set: 0
         JSL $D4CA1D     ; Create gradient
         JSR C31B0E      ; Shift & OBJ & Fade
         JSR C33F99      ; Apply user font
         LDA #$01        ; CGRAM: Refresh
         TSB $45         ; Set NMI flag
         JSR C31368      ; Refresh screen
         LDA #$72        ; C3/ACDC
         STA $27         ; Queue: Sustain menu
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         JSR C307B0      ; Queue cursor OAM
         JMP C33541      ; BRT:1 + NMI

; 72: Sustain Colosseum item menu
C3ACDC:  LDA #$10        ; Description: On
         TRB $45         ; Set menu flag
         STZ $2A         ; List type: Stock
         JSR C30EFD      ; Queue list upload
         JSR C31F64      ; Handle L and R
         BCS C3AD26      ; Exit if pushed
         JSR C37D22      ; Handle D-Pad
         JSR C382F1      ; Load description

; Fork: Handle A
C3ACF0:  LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C3AD14      ; Branch if not
         TDC             ; Clear A
         LDA $4B         ; Selected slot
         TAX             ; Index it
         LDA $1869,X     ; Item in slot
         CMP #$FF        ; None?
         BEQ C3AD0E      ; Fail if so
         STA $0205       ; Set item bet
         JSR C30EB2      ; Sound: Click
         LDA #$75        ; C3/ADB7
         STA $27         ; Queue: Matchup
         STZ $26         ; Next: Fade-out
         RTS

; Fork: Invalid selection
C3AD0E:  JSR C30EC0      ; Play buzzer
         JSR C3305D      ; Pixelate screen

; Fork: Handle B
C3AD14:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C3AD26      ; Exit if not
         JSR C30EA9      ; Sound: Cursor
         LDA #$FF        ; Empty item
         STA $0205       ; Clear item bet
         STA $27         ; Queue menu exit
         STZ $26         ; Next: Fade-out
C3AD26:  RTS

; Draw and upload Colosseum item menu
C3AD27:  LDA #$01        ; 64x32 at $0000
         STA $2107       ; Set BG1 map loc
         LDY #C3AD8E     ; C3/AD8E
         JSR C30341      ; Draw message box
         LDY #C3AD8A     ; C3/AD8A
         JSR C30341      ; Draw title box
         LDY #C3AD92     ; C3/AD92
         JSR C30341      ; Draw desc box
         LDY #C3AD96     ; C3/AD96
         JSR C30341      ; Draw item box
         JSR C30E52      ; Upload windows
         JSR C36A41      ; Clear BG3 map B
         JSR C36A46      ; Clear BG3 map C
         JSR C36A4B      ; Clear BG3 map D
         JSR C3AD6E      ; Draw title, etc.
         JSR C3AD80      ; Draw desc/"Select"
         JSR C3A9A9      ; Upload elements...
         JSR C30E6E      ; Upload BG3 A+B
         JSR C30E7C      ; Upload BG3 C+D
         JSR C36A19      ; Clear BG1 map B
         JSR C37E0D      ; Draw inventory
         JSR C382F1      ; Load description
         JSR C30E28      ; Upload BG1 A+B
         JMP C30E36      ; Upload BG1 C...

; Draw Colosseum menu title, clear tilemap beforehand
C3AD6E:  JSR C36A3C      ; Clear BG3 map A
         LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         LDY #C3AD9A     ; Text pointer
         JSR C302F9      ; Draw "Colosseum"
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         RTS             ; ^ For "Select..."

; Build BG3 tilemap for Colosseum item menu, excluding title
C3AD80:  JSR C3A73D      ; Build desc map
         LDY #C3ADA6     ; Text pointer
         JSR C302F9      ; Draw "Select..."
         RTS

; Window layout for Colosseum item menu
C3AD8A:  dw $588B,$0209  ; 11x04 at $588B (Title)
C3AD8E:  dw $58A1,$0211  ; 19x04 at $58A1 ("Select...")
C3AD92:  dw $598B,$031C  ; 30x05 at $598B (Description)
C3AD96:  dw $5ACB,$0F1C  ; 30x17 at $5ACB (Items)

; Positioned text for Colosseum
C3AD9A:  dw $790D : db "Colosseum",$00
C3ADA6:  dw $7923 : db "Select an Item",$00

; 75: Initialize Colosseum matchup menu
C3ADB7:  JSR C3352F      ; Reset/Stop stuff
         STZ $43         ; Disable HDMA
         JSR C33A87      ; Load skin visuals
         JSR C36915      ; Get party info
         LDA #$02        ; Gradient set: 2
         JSL $D4CA1D     ; Create gradient
         JSR C369DC      ; Queue Win1 HDMA
         JSR C36A66      ; Load GFX/pal/prize
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         JSR C3B323      ; Load navig data
         JSR C3B32C      ; Relocate cursor
         JSR C307B0      ; Queue cursor OAM
         JSR C3AE07      ; Queue "VS" OAM
         JSR C318D1      ; Set to shift text
         JSR C3AE34      ; Draw menu; members
         LDA #$01        ; CGRAM: Refresh
         TSB $45         ; Set NMI flag
         JSR C33F99      ; Apply user font
         LDA #$01        ; Min slot: 8
         LDY #C3B2A5     ; C3/B2A5
         JSR C31173      ; Queue challenger fn
         LDA #$76        ; C3/AE0F
         STA $27         ; Queue: Sustain menu
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         JSR C36904      ; Reset BGs' X/Y
         JSR C30EFD      ; Queue enemy upload
         JSR C33541      ; BRT:1 + NMI
         JMP C30F39      ; Queue text upload

; Queue OAM function for "VS" symbol
C3AE07:  LDA #$01        ; Min slot: 8
         LDY #C3B2F3     ; C3/B2F3
         JMP C31173      ; Queue OAM fn

; 76: Sustain Colosseum matchup menu
C3AE0F:  JSR C30F39      ; Queue text upload
         JSR C3B329      ; Handle D-Pad
         LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C3AE33      ; Exit if not
         JSR C3B2EC      ; Actor in slot
         BMI C3AE2D      ; Fail if nobody
         STA $0208       ; Set challenger
         JSR C30EB2      ; Sound: Click
         LDA #$FF        ; Null value
         STA $27         ; Queue menu exit
         STZ $26         ; Next: Fade-out
         RTS             ; Exit
C3AE2D:  JSR C30EC0      ; Play buzzer
         JSR C3305D      ; Pixelate screen
C3AE33:  RTS

; Draw Colosseum matchup menu and create members
C3AE34:  LDA #$01        ; 64x32 at $0000
         STA $2107       ; Set BG1 map loc
         LDY #C3B33F     ; C3/B33F
         JSR C30341      ; Draw prize window
         LDY #C3B343     ; C3/B343
         JSR C30341      ; Draw bet window
         LDY #C3B347     ; C3/B347
         JSR C30341      ; Draw party window
         JSR C30E52      ; Upload windows
         JSR C36A3C      ; Clear BG3 map A
         LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         JSR C3B17D      ; Create member 1
         JSR C3B197      ; Create member 2
         JSR C3B1B1      ; Create member 3
         JSR C3B1CB      ; Create member 4
         LDY #C3B40F     ; Text pointer
         JSR C302F9      ; Draw "Select..."
         JSR C3B28D      ; Draw enemy name
         JSR C3B24D      ; Draw item bet
         JSR C3B255      ; Draw prize
         JSR C30E6E      ; Upload BG3 A+B
         LDY #$5000      ; $A000
         STY $2116       ; Set VRAM ptr
         JSR C3B10A      ; Blank BG1 tile 1
         JSR C36A15      ; Clear BG1 map A
         JSR C3AE93      ; Handle Striker
         LDA $0201       ; Facing Shadow?
         BNE C3AE8D      ; Branch if so
         JSR C3AF00      ; Draw monster
         JMP C30E28      ; Upload BG1 A+B

; Fork: Fighting Shadow
C3AE8D:  JSR C3AEA7      ; Do name/sprite
         JMP C30E28      ; Upload BG1 A+B

; Check if betting Striker
C3AE93:  LDA $0205       ; Item bet
         CMP #$29        ; Striker?
         BNE C3AEA6      ; Exit if not
         LDA $1EBD       ; Event flags
         AND #$80        ; Shadow at arena?
         BEQ C3AEA6      ; Exit if not
         LDA #$01        ; Facing Shadow: Y
         STA $0201       ; Set arena's mode
C3AEA6:  RTS

; Create Shadow's name and sprite for Colosseum
C3AEA7:  JSR C3AED9      ; Draw "Shadow"
         LDA #$02        ; For C3/7B8F...
         TSB $47         ; See C3/B2BB...
         LDA #$02        ; Min slot: 16
         LDY #C37A5F     ; C3/7A5F
         JSR C31173      ; Queue OAM fn
         LDA #$01        ; OAM mode: 1
         STA $7E3649,X   ; Set sprite's
         LDA $7E364A,X   ; Sprite flags
         ORA #$02        ; Add H-Flip
         STA $7E364A,X   ; Save changes
         TXY             ; Queue index
         LDA #$38        ; Sprite X: 56
         STA $E1         ; Memorize it
         LDA #$68        ; Sprite Y: 104
         STA $E2         ; Memorize it
         TDC             ; Clear A
         LDA #$03        ; Sprite set: 3
         JSR C378FA      ; Set anim ptr
         JSR C3B211      ; Set position
         RTS

; Draw Shadow's name at Colosseum
C3AED9:  TDC             ; Clear A
         TAX             ; 1st: Terra
C3AEDB:  STX $E7         ; Save index
         REP #$20        ; 16-bit A
         LDA.L C36969,X  ; Actor address
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDA $0000,X     ; Actor in slot
         CMP #$03        ; Shadow?
         BEQ C3AEF8      ; Retain if so
         LDX $E7         ; Actor index
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0020      ; Done 16 actors?
         BNE C3AEDB      ; Loop if not
C3AEF6:  BRA C3AEF6      ; Freeze game...
C3AEF8:  STX $67         ; Save actor index
         LDY #$7C11      ; Text position
         JMP C334CF      ; Draw actor name

; Build tilemap for Colosseum enemy
C3AF00:  LDX $91         ; Tilemap ptr
         STX $ED         ; Set dst LBs
         LDA $99         ; Monster size
         CMP #$08        ; 8x8 tiles?
         BEQ C3AF16      ; Branch if so
         LDX #$0010      ; Tiles: 16
         STX $F1         ; Set height
         LDX #$0010      ; ...
         STX $E0         ; Set width
         BRA C3AF1D      ; Skip 3 lines
C3AF16:  LDX #$0008      ; Tiles: 8
         STX $F1         ; Set height
         STX $E0         ; Set width
C3AF1D:  LDA #$7E        ; Bank: 7E
         STA $EF         ; Set dst HB
         REP #$20        ; 16-bit A
         LDA #$2C01      ; Tile 1, pal 3
         STA $E7         ; Priority: Yes
C3AF28:  LDX $E0         ; Width in tiles
         LDY $00         ; Map index: 0
C3AF2C:  LDA $E7         ; Tile attribs
         STA [$ED],Y     ; Put in tilemap
         INY             ; Map index +1
         INY             ; Map index +1
         INC $E7         ; Tile number +1
         DEX             ; One less column
         BNE C3AF2C      ; Loop till last
         LDA $ED         ; Tilemap ptr
         CLC             ; Prepare ADC
         ADC #$0040      ; Go 1 row down
         STA $ED         ; Save changes
         DEC $F1         ; One less row
         BNE C3AF28      ; Loop till last
         SEP #$20        ; 8-bit A
         RTS

; Load prize and enemy data for Colosseum matchup
C3AF46:  JSR C3B22C      ; Set enemy, prize
         LDA $0206       ; Enemy number
         STA $4202       ; Set multiplicand
         LDA #$05        ; Enemy data size
         STA $4203       ; Set multiplier
         LDY #$5010      ; $A020
         STY $2116       ; Set VRAM ptr
         NOP
         NOP
         LDX $4216       ; Index product
         LDA $D27000,X   ; GFX ptr/8 LSBs
         STA $E7         ; Save in RAM
         LDA $D27001,X   ; Ptr MSBs; flag
         STA $E8         ; Save in RAM
         LDA $D27002,X   ; Pal/Mold info
         STA $F2         ; Save in RAM
         LDA $D27003,X   ; Palette LSBs
         STA $F1         ; Save in RAM
         LDA $D27004,X   ; Mold index LSBs
         STA $E9         ; Save in RAM

; Fork: Relocate color depth flag
C3AF7D:  LDA $E8         ; 8-color palette?
         BMI C3AF85      ; Branch if so
         STZ $FF         ; Colors: 16
         BRA C3AF8D      ; Skip other case
C3AF85:  LDA #$01        ; Colors: 8
         STA $FF         ; Set color depth
         LDA #$80        ; 8-color flag
         TRB $E8         ; Clear original

; Fork: Compute enemy graphics address ($E97000+8X)
C3AF8D:  LDA #$E9        ; Bank: E9
         STA $F7         ; Set base adr HB
         REP #$20        ; 16-bit A
         LDA #$7000      ; E9/7000
         STA $F5         ; Set base adr LBs
         LDA $E7         ; GFX ptr / 8
         STA $F9         ; Init real ptr
         STZ $FB         ; Clear HBs
         ASL $F9         ; Ptr LBs x2
         ROL $FB         ; Ptr HBs x2 + C
         ASL $F9         ; Ptr LBs x2
         ROL $FB         ; Ptr HBs x2 + C
         ASL $F9         ; Ptr LBs x2
         ROL $FB         ; Ptr HBs x2 + C
         CLC             ; Prepare ADC
         LDA $F9         ; GFX pointer LBs
         ADC $F5         ; Add base address
         STA $F5         ; Set address LBs
         LDA $FB         ; GFX pointer HB
         ADC $F7         ; Add base address
         STA $F7         ; Set address HB
         LDX $00         ; GFX index: 0

; Fork: Set address pointer and size for 8x8 mold data
C3AFB9:  SEP #$20        ; 8-bit A
         LDA $F2         ; 16x16 image?
         BMI C3AFC8      ; Branch if so
         LDY #$A820      ; D2/A820
         STY $E3         ; Set address ptr
         LDA #$08        ; 8-tile rows: 8
         BRA C3AFCF      ; Set data size

; Fork: Set address pointer and size for 16x16 mold data
C3AFC8:  LDY #$A822      ; D2/A822
         STY $E3         ; Set address ptr
         LDA #$20        ; 8-tile rows: 32
C3AFCF:  STA $E6         ; Set rows left
         STA $99         ; Set enemy size
         LDA #$D2        ; Bank: D2
         STA $E5         ; Set pointer HB

; Fork: Define mold index's high byte
C3AFD7:  LDA $F2         ; Monster flags
         AND #$40        ; Mold index MSB
         ROL A           ; Put in bit 7
         ROL A           ; Put in Carry
         ROL A           ; Put in bit 0
         STA $EA         ; Set index HB

; Fork: Load address to 8x8 enemy's mold ($D2A824+8X)
C3AFE0:  LDA $F2         ; 16x16 image?
         BMI C3AFED      ; Branch if so
         REP #$20        ; 16-bit A
         LDA $E9         ; Mold index
         ASL A           ; x2
         ASL A           ; x4
         ASL A           ; x8
         BRA C3AFF6      ; Set address

; Fork: Load address to 16x16 enemy's mold ($D2AC24+32X)
C3AFED:  REP #$20        ; 16-bit A
         LDA $E9         ; Mold index
         ASL A           ; x2
         ASL A           ; x4
         ASL A           ; x8
         ASL A           ; x16
         ASL A           ; x32
C3AFF6:  CLC             ; Prepare ADC
         ADC [$E3]       ; Add base adr
         STA $E0         ; Set src LBs
         SEP #$20        ; 8-bit A
         LDA #$D2        ; Bank: D2
         STA $E2         ; Set src HB

; Fork: Load 8-tile row, blank tiles excluded from mold
C3B001:  LDY #$0008      ; Columns: 8
         PHX             ; Save GFX index
         TDC             ; Clear A
         LDA $E6         ; Rows left
         TAX             ; Index it
         LDA [$E0]       ; Mold row flags
         STA $7E9D88,X   ; For centering
         PLX             ; GFX index
C3B010:  CLC             ; Prepare ROL
         PHY             ; Save column
         ROL A           ; Blank tile here?
         PHA             ; Save mold flags
         BCC C3B01B      ; Branch if blank
         JSR C3B11E      ; Load tile's GFX
         BRA C3B01E      ; Skip a line
C3B01B:  JSR C3B10A      ; Make blank tile
C3B01E:  PLA             ; Mold row flags
         PLY             ; Columns left
         DEY             ; One less left
         BNE C3B010      ; Loop till last

; Fork: Handle next 8-tile row
C3B023:  REP #$20        ; 16-bit A
         INC $E0         ; Mold data adr +1
         SEP #$20        ; 8-bit A
         DEC $E6         ; One less row
         BNE C3B001      ; Loop till last

; Fork: Set position and load colors
C3B02D:  JSR C3B033      ; Set tilemap ptr
         JMP C3B15A      ; Load enemy pal

; Position Colosseum enemy based on size
C3B033:  STZ $E0         ; Blank rows: 0
         STZ $E4         ; Rel pos LB: 0
         STZ $E5         ; Rel pos HB: 0
         STZ $E3         ; Clear filled cols
         LDX $00         ; 1st: Bottom row
         LDA $99         ; Monster size
         CMP #$08        ; 8x8 tiles?
         BNE C3B079      ; Branch if not

; Fork: Count blank rows, identify filled columns (8x8)
C3B043:  LDA $7E9D89,X   ; Blank row here?
         BNE C3B050      ; Branch if not
         INC $E0         ; Blank rows +1
         INX             ; Point 1 row up
         CMP #$08        ; Bogus...
         BNE C3B043      ; Test next row
C3B050:  LDX $00         ; 1st: Bottom row
C3B052:  LDA $7E9D89,X   ; Row's filled cols
         ORA $E3         ; Add prior rows'
         STA $E3         ; Save merged rows
         INX             ; Point 1 row up
         CPX #$0008      ; Done all 8 rows?
         BNE C3B052      ; Loop if not

; Fork: Position 8x8 enemy based on empty columns
C3B060:  ROR $E3         ; Empty column here?
         BCS C3B068      ; Branch if not
         INC $E4         ; Relative pos +1
         BRA C3B060      ; Test next column
C3B068:  LSR $E4         ; If odd-numbered:
         ASL $E4         ; Relative pos -1
         REP #$21        ; 16-bit A; C-
         LDA $E4         ; Relative position
         ADC #$3A51      ; X+4, Y+8 tiles
         STA $E7         ; Save tilemap ptr
         SEP #$20        ; 8-bit A
         BRA C3B0B4      ; Adjust Y position

; Fork: Count blank rows, identify R-Half's filled columns (16x16)
C3B079:  LDA $7E9D89,X   ; Row's right half
         ORA $7E9D8A,X   ; L-Half empty too?
         BNE C3B08C      ; Branch if not
         INC $E0         ; Blank rows +1
         INX             ; 8-tile index +1
         INX             ; 8-tile index +1
         CPX #$0020      ; Done all 16 rows?
         BNE C3B079      ; Loop if not
C3B08C:  LDX $00         ; 1st: Bottom row
C3B08E:  LDA $7E9D89,X   ; R-Half filled cols
         ORA $E3         ; Add prior rows'
         STA $E3         ; Save merged rows
         INX             ; 8-tile index +1
         INX             ; 8-tile index +1
         CPX #$0020      ; Done all 16 rows?
         BNE C3B08E      ; Loop if not

; Fork: Position 16x16 enemy based on empty columns
C3B09D:  ROR $E3         ; Empty column?
         BCS C3B0A5      ; Branch if not
         INC $E4         ; Relative pos +1
         BRA C3B09D      ; Test next column
C3B0A5:  LSR $E4         ; If odd-numbered:
         ASL $E4         ; Relative pos -1
         REP #$21        ; 16-bit A; C-
         LDA $E4         ; Relative position
         ADC #$3849      ; Add base address
         STA $E7         ; Save tilemap ptr
         SEP #$20        ; 8-bit A
C3B0B4:  JMP C3B0B7      ; ...

; Fork: Adjust Y position based on enemy and blank rows
C3B0B7:  TDC             ; Clear A
         LDA $0206       ; Enemy number
         TAX             ; Index it
         LDA $ECE800,X   ; Modifier index
         REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         JMP (C3B0C9,X)  ; Shift enemy

; Jump table for the above
C3B0C9:  dw C3B0D3       ; Shift up by 3
         dw C3B0F8       ; Shift down by $E0
         dw C3B0E2       ; Shift down by $E0 - 1
         dw C3B0EA       ; Shift down by $E0 + 1
         dw C3B0EE       ; Shift down by $E0 - 3

; Shift enemy up by 3 tiles
C3B0D3:  STZ $E0         ; Blank rows: 0
         REP #$20        ; 16-bit A
         LDA $E7         ; Tilemap ptr
         SEC             ; Prepare SBC
         SBC #$00C0      ; Go 3 rows up
         STA $91         ; Save map ptr
         SEP #$20        ; 8-bit A
         RTS

; Shift enemy down by $E0 - 1
C3B0E2:  DEC $E0         ; Blank rows -1
         BPL C3B0E8      ; Branch if 0+
         STZ $E0         ; Blank rows: 0
C3B0E8:  BRA C3B0F8      ; Shift enemy

; Shift enemy down by $E0 + 1
C3B0EA:  INC $E0         ; Blank rows +1
         BRA C3B0F8      ; Shift enemy

; Shift enemy down by $E0 - 3
C3B0EE:  DEC $E0         ; Blank rows -1
         DEC $E0         ; Blank rows -1
         DEC $E0         ; Blank rows -1
         BPL C3B0F8      ; Branch if 0+
         STZ $E0         ; Blank rows: 0

; Shift enemy down by $E0
C3B0F8:  TDC             ; ...
         LDA $E0         ; Blank rows
         REP #$21        ; 16-bit A; C-
         ASL A           ; x2
         ASL A           ; x4
         ASL A           ; x8
         ASL A           ; x16
         ASL A           ; x32
         ASL A           ; x64
         ADC $E7         ; Add map ptr
         STA $91         ; Save map ptr
         SEP #$20        ; 8-bit A
         RTS

; Create a blank tile at current location in VRAM
C3B10A:  LDY #$0010      ; Rows: 8
         STY $E3         ; Set loop limit
         REP #$20        ; 16-bit A
         LDY $00         ; Loop count: 0
C3B113:  STZ $2118       ; 8 px, 2 planes
         INY             ; Loop count +1
         CPY $E3         ; Done 8 rows?
         BNE C3B113      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Upload current tile from monster's tileset
C3B11E:  LDA $FF         ; Has 8 colors?
         BNE C3B129      ; Branch if so
         LDY #$0010      ; Bytes: 32
         STY $E3         ; Set loop limit
         BRA C3B145      ; Load tile GFX

; Fork: Load 8-color tile, encode as 4bpp
C3B129:  LDY #$0008      ; Bytes: 16
         STY $E3         ; Set loop limit
         JSR C3B145      ; Load rows' LSBs
         TXY             ; ...
         LDX #$0008      ; Rows left: 8
         TDC             ; Clear A
C3B136:  LDA [$F5],Y     ; GFX row's MSBs
         REP #$20        ; 16-bit A
         STA $2118       ; Save in VRAM
         SEP #$20        ; 8-bit A
         INY             ; GFX index +1
         DEX             ; One less row
         BNE C3B136      ; Loop till last
         TYX             ; GFX index
         RTS

; Fork: Upload specified number of words
C3B145:  TXY             ; GFX index
         LDX $00         ; Loop count: 0
         REP #$20        ; 16-bit A
C3B14A:  LDA [$F5],Y     ; 8 px, 2 planes
         STA $2118       ; Save in VRAM
         INY             ; GFX index +1
         INY             ; GFX index +1
         INX             ; Loop count +1
         CPX $E3         ; Beyond range?
         BNE C3B14A      ; Loop if not
         SEP #$20        ; 8-bit A
         TYX             ; GFX index
         RTS

; Load monster's palette
C3B15A:  REP #$20        ; 16-bit A
         LDA $F1         ; Palette index
         AND #$03FF      ; Clear flags
         ASL A           ; x2
         ASL A           ; x4
         ASL A           ; x8
         ASL A           ; x16
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDY #$30A9      ; 7E/30A9
         STY $2181       ; Set WRAM LBs
         LDY #$0020      ; Colors: 16
C3B171:  LDA $D27820,X   ; Color data
         STA $2180       ; To BG pal 3
         INX             ; ROM index +1
         DEY             ; One less byte
         BNE C3B171      ; Loop till last
         RTS

; Create Colosseum member 1
C3B17D:  LDY $6D         ; Actor's address
         BEQ C3B196      ; Exit if nobody
         STY $67         ; Memorize it
         LDY #$7E4F      ; Text position
         JSR C3B1E5      ; Draw name; OAM
         LDA #$20        ; Sprite's X: 32
         STA $E1         ; Memorize it
         LDA #$A8        ; Sprite's Y: 168
         STA $E2         ; Memorize it
         LDA $69         ; Actor's slot
         JSR C3B1F3      ; Init sprite
C3B196:  RTS

; Create Colosseum member 2
C3B197:  LDY $6F         ; Actor's address
         BEQ C3B1B0      ; Exit if nobody
         STY $67         ; Memorize it
         LDY #$7E5D      ; Text position
         JSR C3B1E5      ; Draw name; OAM
         LDA #$58        ; Sprite's X: 88
         STA $E1         ; Memorize it
         LDA #$A8        ; Sprite's Y: 168
         STA $E2         ; Memorize it
         LDA $6A         ; Actor
         JSR C3B1F3      ; Init sprite
C3B1B0:  RTS

; Create Colosseum member 3
C3B1B1:  LDY $71         ; Actor's address
         BEQ C3B1CA      ; Exit if nobody
         STY $67         ; Memorize it
         LDY #$7E6B      ; Text position
         JSR C3B1E5      ; Draw name; OAM
         LDA #$90        ; Sprite's X: 144
         STA $E1         ; Memorize it
         LDA #$A8        ; Sprite's Y: 168
         STA $E2         ; Memorize it
         LDA $6B         ; Actor's slot
         JSR C3B1F3      ; Init sprite
C3B1CA:  RTS

; Create Colosseum member 4
C3B1CB:  LDY $73         ; Actor's address
         BEQ C3B1E4      ; Exit if nobody
         STY $67         ; Memorize it
         LDY #$7E79      ; Text position
         JSR C3B1E5      ; Draw name; OAM
         LDA #$C8        ; Sprite's X: 200
         STA $E1         ; Memorize it
         LDA #$A8        ; Sprite's Y: 168
         STA $E2         ; Memorize it
         LDA $6C         ; Actor's slot
         JSR C3B1F3      ; Init sprite
C3B1E4:  RTS

; Draw Colosseum member's name, queue sprite function
C3B1E5:  JSR C334CF      ; Draw actor name
         LDA #$02        ; Min slot: 16
         LDY #C37A5F     ; C3/7A5F
         JSR C31173      ; Queue OAM fn
         TXY             ; Queue index
         TDC             ; Clear A
         RTS

; Initialize Colosseum actor sprite, excluding enemy Shadow
C3B1F3:  ASL A           ; Actor x2
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C36969,X  ; Actor address
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDA $0014,X     ; Status
         AND #$20        ; Imp?
         BEQ C3B20A      ; Branch if not
         TDC             ; Clear A
         LDA #$0F        ; Use Imp set
         BRA C3B20E      ; Skip 2 lines
C3B20A:  TDC             ; Clear A
         LDA $0001,X     ; Sprite set
C3B20E:  JSR C378FA      ; Set anim ptr
C3B211:  LDA #$D8        ; Bank: D8
         STA $35CA,Y     ; Set ptr HB
         LDA $E1         ; X position
         STA $33CA,Y     ; Set sprite's
         LDA $E2         ; Y position
         STA $344A,Y     ; Set sprite's
         TDC             ; Clear A
         STA $33CB,Y     ; No use...
         STA $344B,Y     ; No use...
         LDA #$00        ; Clear A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         RTS

; Load opponent and prize data for item bet
C3B22C:  TDC             ; Clear A
         LDA $0205       ; Item bet
         REP #$20        ; 16-bit A
         ASL A           ; x2
         ASL A           ; x4
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDA $DFB600,X   ; Opponent
         STA $0206       ; Save in RAM
         LDA $DFB602,X   ; Prize
         STA $0207       ; Save in RAM
         LDA $DFB603,X   ; Hide Prize flag
         STA $0209       ; Save in RAM
         RTS             ; ^ Read below

; Draw Colosseum bet
C3B24D:  LDA $0205       ; Item bet
         LDX #$792B      ; Text position
         BRA C3B263      ; Draw item name

; Draw Colosseum prize
C3B255:  LDA $0209       ; Hide prize?
         BEQ C3B25D      ; Branch if not
         JMP C3B286      ; Draw "???..."
C3B25D:  LDA $0207       ; Prize
         LDX #$790D      ; Tilemap ptr
C3B263:  PHA             ; Save item
         LDY #$9E8B      ; 7E/9E8B
         STY $2181       ; Set WRAM LBs
         REP #$20        ; 16-bit A
         TXA             ; Tilemap ptr
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
C3B273:  LDA $4212       ; PPU status
         AND #$40        ; H-Blank?
         BEQ C3B273      ; Loop if not
         PLA             ; Item
         JSR C380CE      ; Load "<item>:"
         TDC             ; Terminator
         STA $7E9E98     ; Remove ":"
         JMP C37FD9      ; Draw item name

; Fork: Draw question marks
C3B286:  LDY #C3B427     ; Text pointer
         JSR C302F9      ; Draw string
         RTS

; Draw monster's name for Colosseum
C3B28D:  REP #$20        ; 16-bit A
         LDA #$7C4F      ; Tilemap ptr
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         JSR C35409      ; Define source
         TDC             ; ...
         LDA $0206       ; Opponent
         JSR C38467      ; Load name
         JMP C37FD9      ; Draw name

; Update Colosseum challenger's name and sprite
C3B2A5:  PHB             ; Save DB
         LDA #$00        ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         ASL A           ; Double it
         TAX             ; Index it
         LDY $6D,X       ; Actor address
         BEQ C3B2DF      ; Blank if nobody
         STY $67         ; Memorize it
         LDY #$7C75      ; Text position
         JSR C334CF      ; Draw actor name
         LDA #$02        ; Temp sprite: Y
         TSB $47         ; Set menu flag
         LDA #$02        ; Min slot: 16
         LDY #C37B42     ; C3/7B42
         JSR C31173      ; Queue OAM fn
         LDA #$01        ; Anim mode: 1
         STA $7E3649,X   ; Set sprite's
         TXY             ; Queue index
         TDC             ; Clear A
         LDA #$B8        ; Sprite's X: 184
         STA $E1         ; Memorize it
         LDA #$68        ; Sprite's Y: 104
         STA $E2         ; Memorize it
         JSR C3B2EC      ; Actor's slot
         JSR C3B1F3      ; Init sprite
         BRA C3B2E2      ; Skip a line
C3B2DF:  JSR C3B2E5      ; Blank name
C3B2E2:  PLB             ; Restore DB
         SEC             ; Set to requeue
         RTS

; Blank challenger's name
C3B2E5:  LDY #C3B406     ; Text pointer
         JSR C302F9      ; Draw 6 spaces
         RTS

; Get party actor indicated by cursor
C3B2EC:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
         TAX             ; Index it
         LDA $69,X       ; Actor slot
         RTS

; Update "VS" symbol from Colosseum
C3B2F3:  TAX             ; Index mode
         JMP (C3B2F7,X)  ; Handle mode

; Jump table for the above
C3B2F7:  dw C3B2FB       ; Initialize sprite
         dw C3B31E       ; Sustain sprite

; Mode 0: Initialize sprite
C3B2FB:  LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         LDA #$EC87      ; Anim table ptr
         STA $32C9,X     ; Set sprite's
         LDA #$0070      ; X: 112
         STA $33CA,X     ; Set sprite's
         LDA #$0060      ; Y: 96
         STA $344A,X     ; Set sprite's
         SEP #$20        ; 8-bit A
         INC $3649,X     ; Mode +1
         LDA #$D8        ; Bank: D8
         STA $35CA,X     ; Set ptr HB
         JSR C31206      ; Set pose timer

; Mode 1: Sustain sprite
C3B31E:  JSR C31221      ; Define OAM
         SEC             ; Set to requeue
         RTS

; Load navigation data for Colosseum matchup menu
C3B323:  LDY #C3B332     ; C3/B332
         JMP C305FE      ; Load navig data

; Handle D-Pad for Colosseum matchup menu
C3B329:  JSR C3072D      ; Handle D-Pad
C3B32C:  LDY #C3B337     ; C3/B337
         JMP C30640      ; Relocate cursor

; Navigation data for Colosseum matchup menu
C3B332:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $04          ; 4 columns
         db $01          ; 1 row

; Cursor positions for Colosseum matchup menu
C3B337:  dw $B010        ; Member 1
         dw $B048        ; Member 2
         dw $B080        ; Member 3
         dw $B0B8        ; Member 4

; Window layout for Colosseum matchup menu
C3B33F:  dw $588B,$020D  ; 15x4 at $588B (Prize)
C3B343:  dw $58A9,$020D  ; 15x4 at $58A9 (Bet)
C3B347:  dw $5CCB,$071C  ; 30x9 at $5CCB (Party)

; Load arena graphics, tilemap, and colors
C3B34B:  REP #$20        ; 16-bit A
         LDA $E7168C     ; E8/0C49
         STA $F3         ; Set src LBs
         SEP #$20        ; 8-bit A
         LDA $E7168E     ; Bank: E8
         STA $F5         ; Set src HB
         JSR C3B3F2      ; Unpack GFX A
         LDY #$6800      ; $D000
         STY $2116       ; Set VRAM ptr
         LDY #$1000      ; End: 7E/C68C
         STY $E7         ; Set src end
         LDX $00         ; 1st: 7E/B68D
         JSR C3B3C6      ; Upload GFX A

; Fork: Unpack and upload graphics for upper half
C3B36E:  REP #$20        ; 16-bit A
         LDA $E71692     ; E8/1841
         STA $F3         ; Set src LBs
         SEP #$20        ; 8-bit A
         LDA $E71694     ; Bank: E8
         STA $F5         ; Set src HB
         JSR C3B3F2      ; Unpack GFX B
         LDY #$7000      ; $E000
         STY $2116       ; Set VRAM ptr
         LDY #$1000      ; End: 7E/C68C
         STY $E7         ; Set src end
         LDX $00         ; 1st: 7E/B68D
         JSR C3B3C6      ; Upload GFX B

; Fork: Unpack battle tilemap, convert to menu format
C3B391:  REP #$20        ; 16-bit A
         LDA $E7187A     ; E7/652B
         STA $F3         ; Set src LBs
         SEP #$20        ; 8-bit A
         LDA #$E7        ; Bank: E7
         STA $F5         ; Set src HB
         JSR C3B3F2      ; Unpack map
         JSR C3B3D8      ; Convert map

; Fork: Load colors
C3B3A5:  REP #$20        ; 16-bit A
         LDA #$0AB0      ; E7/0AB0
         STA $E7         ; Set src LBs
         SEP #$20        ; 8-bit A
         LDA #$E7        ; Bank: E7
         STA $E9         ; Set src HB
         LDX #$30C9      ; 7E/30C9
         STX $2181       ; Set WRAM LBs
         LDY $00         ; Index: 0
C3B3BA:  LDA [$E7],Y     ; Color data
         STA $2180       ; To BG pal 4/5/6
         INY             ; Index +1
         CPY #$0060      ; Done 48 colors?
         BNE C3B3BA      ; Loop if not
         RTS

; Upload current graphics set for arena background
C3B3C6:  REP #$20        ; 16-bit A
C3B3C8:  LDA $7EB68D,X   ; 8 px, 2 planes
         STA $2118       ; Save in VRAM
         INX             ; Index +1
         INX             ; Index +1
         CPX $E7         ; Past range?
         BNE C3B3C8      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Convert and relocate decompressed arena tilemap
C3B3D8:  LDX $00         ; Index: 0
         REP #$20        ; 16-bit A
C3B3DC:  LDA $7EB68D,X   ; Attributes
         SEC             ; Prepare SBC
         SBC #$0380      ; Tile num -896
         STA $7E5949,X   ; Put in BG2a
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0580      ; Done 704?
         BNE C3B3DC      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Decompress data for arena background
C3B3F2:  LDY #$B68D      ; 7E/B68D
         STY $F6         ; Set dst LBs
         LDA #$7E        ; Bank: 7E
         STA $F8         ; Set dst HB
         PHB             ; Save DB
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         JSL $C2FF6D     ; Unpack data
         PLB             ; Restore DB
         RTS

; Positioned spaces for blanking challenger's name
C3B406:  dw $7C75 : db "      ",$00

; Positioned Colosseum text
C3B40F:  dw $7D15 : db "Select the challenger",$00
C3B427:  dw $790D : db "?????????????",$00

; Clear buffer for storing element graphics (4 tiles)
C3B437:  TDC             ; Clear A
         TAX             ; Index: 0
         REP #$20        ; 16-bit A
C3B43B:  STA $7EA271,X   ; Clear a word
         INX             ; Index +1
         INX             ; Index +1
         CPX $F3         ; Past range?
         BNE C3B43B      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; OAM for small white arrow in actor naming menu
C3B448:  db $01          ; Tiles: 1
         dw $0009        ; 8x8, X+9, Y+0
         dw $3E02        ; Tile 2, pal 7, prio 3

; OAM for small black arrow in actor naming menu
C3B44D:  db $01          ; Tiles: 1
         dw $0009        ; 8x8, X+9, Y+0
         dw $3E12        ; Tile 18, pal 7, prio 3

; Animation table for small arrow in actor naming menu
C3B452:  dw C3B448       ; White arrow
         db $02          ; Frames: 2
         dw C3B44D       ; Black arrow
         db $02          ; Frames: 2
         dw C3B448       ; Bogus...
         db $FF          ; Loop

; OAM for blanking Config's large arrow (SFC: Naming menus' too)
C3B45B:  db $00          ; Tiles: 0

; OAM for large downward arrow in SwdTech naming menu (SFC)
C3B45C:  db $01          ; Tiles: 1
         dw $8280        ; 16x16, X+0, Y+130
         dw $3E03        ; Tile 3, pal 7, prio 3

; OAM for large upward arrow
C3B461:  db $01          ; Tiles: 1
         dw $0080        ; 16x16, X+0, Y+0
         dw $BE03        ; Tile 3, pal 7, prio 3, V-Flip

; 24: Initialize shop menu
C3B466:  JSR C3352F      ; Reset/Stop stuff
         JSR C36904      ; Reset BGs' X/Y
         JSR C36A08      ; Set Win1 bounds
         LDA #$03        ; 64x64 at $0000
         STA $2107       ; Set BG1 map loc
         LDA #$C0        ; Channels: 6, 7
         TRB $43         ; Halt HDMA 6+7...
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         STZ $4A         ; Sell list scroll: 0
         JSR C3B886      ; Load navig data
         JSR C3B88F      ; Relocate cursor
         JSR C307B0      ; Queue cursor OAM
         JSR C3B8C4      ; Draw menu; desc
         JSR C37E2B      ; Set to shift text
         JSR C3C018      ; Adjust BG3 shifting
         LDA #$25        ; C3/B49B
         STA $27         ; Queue: Sustain menu
         LDA #$01        ; C3/1D7E
         STA $26         ; Next: Fade-in
         JMP C33541      ; BRT:1 + NMI

; 25: Sustain main shop menu
C3B49B:  JSR C3B88C      ; Handle D-Pad
         LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C3B4AA      ; Branch if not
         JSR C30EB2      ; Sound: Click
         JMP C3B792      ; Handle choice

; Fork: Handle B
C3B4AA:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C3B4BC      ; Exit if not
         JSR C30EA9      ; Sound: Cursor
C3B4B3:  STZ $0205       ; Never read...
         LDA #$FF        ; Null value
         STA $27         ; Queue menu exit
         STZ $26         ; Next: Fade-out
C3B4BC:  RTS

; 26: Handle buy item list
C3B4BD:  LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         JSR C30F39      ; Queue text upload
         JSR C3B8A6      ; Handle D-Pad
         JSR C3BC84      ; Draw qty owned
         JSR C3BCA8      ; Draw qty worn

; Fork: Handle B
C3B4CD:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C3B4D9      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         JMP C3B760      ; Exit submenu

; Fork: Handle A
C3B4D9:  LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C3B4E5      ; Exit if not
         JSR C3B82F      ; Set buy limit
         JSR C3B7E6      ; Test GP, stock
C3B4E5:  RTS

; Set description to be displayed and to ignore joypad
C3B4E6:  LDA #$10        ; Description: On
         TRB $45         ; Set menu flag
         LDA #$20        ; D-Pad: Ignore
         TSB $45         ; Set desc flag
         RTS

; Load item description for Buy menu
C3B4EF:  JSR C38308      ; Set desc ptrs
         JSR C3BFC2      ; Selected item
         JMP C35738      ; Load description

; Load item description for Sell menu
C3B4F8:  JSR C38308      ; Set desc ptrs
         TDC             ; Clear A
         LDA $4B         ; Selected slot
         TAX             ; Index it
         LDA $1869,X     ; Item in slot
         JMP C35738      ; Load description

; 27: Handle buy order menu
C3B505:  JSR C3B4E6      ; Set desc flags
         JSR C3B4EF      ; Load description
         JSR C3BB53      ; Get order value
         JSR C3BBAE      ; Draw size, value

; Fork: Buy quantity +1
C3B511:  LDA $0B         ; Semi-auto keys
         BIT #$01        ; Pushing right?
         BEQ C3B539      ; Branch if not
         JSR C30EA3      ; Sound: Cursor
         LDA $28         ; Buy quantity
         CMP $6A         ; At capacity?
         BEQ C3B57C      ; Abort if so
         INC $28         ; Quantity +1
         JSR C3BB53      ; Get new cost
         LDA $1860       ; Gold LB
         CMP $F1         ; C- if < cost's
         LDA $1861       ; Gold MB
         SBC $F2         ; C- if < cost's
         LDA $1862       ; Gold HB
         SBC $F3         ; So, GP < cost?
         BCS C3B538      ; Exit if not
         DEC $28         ; Quantity -1
C3B538:  RTS

; Fork: Buy quantity -1
C3B539:  LDA $0B         ; Semi-auto keys
         BIT #$02        ; Pushing left?
         BEQ C3B54A      ; Branch if not
         JSR C30EA3      ; Sound: Cursor
         LDA $28         ; Buy quantity
         CMP #$01        ; One?
         BEQ C3B59E      ; Abort if so
         DEC $28         ; Quantity -1

; Fork: Buy quantity +10
C3B54A:  LDA $0B         ; Semi-auto keys
         BIT #$08        ; Pushing up?
         BEQ C3B583      ; Branch if not
         JSR C30EA3      ; Sound: Cursor
         LDA #$0A        ; Quantity: 10
         CLC             ; Prepare ADC
         ADC $28         ; Add order size
         CMP $6A         ; At capacity?
         BEQ C3B55E      ; Retain if so
         BCS C3B57F      ; Abort if over
C3B55E:  STA $28         ; Set order size
         JSR C3BB53      ; Get new cost
         LDA $1860       ; Gold LB
         CMP $F1         ; C- if < cost's
         LDA $1861       ; Gold MB
         SBC $F2         ; C- if < cost's
         LDA $1862       ; Gold HB
         SBC $F3         ; So, GP < cost?
         BCS C3B57B      ; Exit if not
         LDA $28         ; Buy quantity
         SEC             ; Prepare SBC
         SBC #$0A        ; Subtract 10
         STA $28         ; Save changes
C3B57B:  RTS

; Fork: Go to handler for B
C3B57C:  JMP C3B59E      ; Handle B

; Fork: Leave quantity unchanged...
C3B57F:  LDA $28         ; Buy quantity
         BRA C3B55E      ; Test cost

; Fork: Buy quantity -10
C3B583:  LDA $0B         ; Semi-auto keys
         BIT #$04        ; Pushing down?
         BEQ C3B59E      ; Branch if not
         JSR C30EA3      ; Sound: Cursor
         LDA $28         ; Buy quantity
         SEC             ; Prepare SBC
         SBC #$0A        ; Subtract 10
         BMI C3B59A      ; Use 1 if < 0
         CMP #$01        ; Down to zero?
         BCC C3B59E      ; Abort if so
         STA $28         ; Save changes
         RTS

; Fork: Set buy quantity to 1
C3B59A:  LDA #$01        ; Quantity: 1
         STA $28         ; Set order size

; Fork: Handle B
C3B59E:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C3B5AA      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         JMP C3B7B3      ; Exit submenu

; Fork: Handle A
C3B5AA:  LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C3B5B6      ; Exit if not
         JSR C30ECE      ; Sound: Cash
         JSR C3B5B7      ; ...
C3B5B6:  RTS             ; ...
C3B5B7:  JSR C3BFC2      ; Bought item
         LDY $00         ; Item slot: 1
C3B5BC:  CMP $1869,Y     ; Slot holds it?
         BEQ C3B5E1      ; Qty +1 if so
         INY             ; Item slot +1
         CPY #$0100      ; Done all 256?
         BNE C3B5BC      ; Loop if not
         LDY $00         ; Item slot: 1
C3B5C9:  LDA $1869,Y     ; Item in slot
         CMP #$FF        ; None?
         BEQ C3B5D3      ; Overwrite if so
         INY             ; Item slot +1
         BRA C3B5C9      ; Try next slot

; Fork: Put bought item in empty slot
C3B5D3:  LDA $28         ; Quantity bought
         STA $1969,Y     ; Assign to slot
         LDA $7E9D89,X   ; Bought item
         STA $1869,Y     ; Assign to slot
         BRA C3B5EA      ; Reduce GP, etc.

; Fork: Add quantity bought to stock
C3B5E1:  LDA $28         ; Quantity bought
         CLC             ; Prepare ADC
         ADC $1969,Y     ; Add qty owned
         STA $1969,Y     ; Set qty owned

; Fork: Reduce party's GP, leave submenu
C3B5EA:  JSR C3BB53      ; Get order value
         SEC             ; Prepare SBC
         LDA $1860       ; Gold LB
         SBC $F1         ; Deduct cost's
         STA $1860       ; Save changes
         REP #$20        ; 16-bit A
         LDA $1861       ; Gold HBs
         SBC $F2         ; Deduct cost's
         STA $1861       ; Save changes
         SEP #$20        ; 8-bit A
         JSR C332CE      ; Cap GP
         LDY #C3C3BD     ; Text pointer
         JSR C302F9      ; Draw "Bye!"
         JMP C3B87D      ; Set to exit

; 28: Return to Buy menu after delay
C3B60E:  LDA $20         ; Delay expired?
         BNE C3B615      ; Exit if not
         JSR C3B7B3      ; Leave submenu
C3B615:  RTS

; 29: Handle sell item list
C3B616:  LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         TDC             ; Clear A
         STA $2A         ; List type: Stock
         JSR C30EFD      ; Queue list upload
         JSR C31F64      ; Handle L and R
         BCS C3B675      ; Exit if pushed
         JSR C37D22      ; Handle D-Pad

; Fork: Handle B
C3B628:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C3B634      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         JMP C3B760      ; Exit submenu

; Fork: Handle A
C3B634:  LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C3B675      ; Exit if not
         JSR C3BFCB      ; Selected item
         CMP #$FF        ; Empty slot?
         BEQ C3B66F      ; Fail if so
         JSR C30EB2      ; Sound: Click
         LDA #$C0        ; Scrollbar: Off
         TRB $46         ; Set anim index
         JSR C36A15      ; Blank item list
         JSR C30EFD      ; Set to upload it
         JSR C31368      ; Upload it now
         LDA #$2A        ; C3/B676
         STA $26         ; Next: Order menu
         LDX #$0008      ; X: 8
         STX $55         ; Set cursor's
         LDX #$0034      ; Y: 52
         STX $57         ; Set cursor's
         JSR C3BAA5      ; Draw blue text
         JSR C3BAD3      ; Draw item info
         LDY #C3C3B1     ; Text pointer
         JSR C302F9      ; Draw "How many?"
         JSR C3B86D      ; Switch screen
         RTS

; Fork: Invalid selection
C3B66F:  JSR C30EC0      ; Play buzzer
         JSR C3305D      ; Pixelate screen
C3B675:  RTS

; 2A: Handle sell order menu
C3B676:  JSR C3B4E6      ; Set desc flags
         JSR C3B4F8      ; Load description
         JSR C3BB65      ; Get order value
         JSR C3BBB7      ; Draw qty, offer

; Fork: Sell quantity +1
C3B682:  LDA $0B         ; Semi-auto keys
         BIT #$01        ; Pushing right?
         BEQ C3B695      ; Branch if not
         JSR C30EA3      ; Sound: Cursor
         LDA $28         ; Sell quantity
         CMP $64         ; Can sell more?
         BEQ C3B6E0      ; Abort if not
         INC $28         ; Quantity +1
         BRA C3B6E0      ; Handle B

; Fork: Sell quantity -1
C3B695:  LDA $0B         ; Semi-auto keys
         BIT #$02        ; Pushing left?
         BEQ C3B6A6      ; Branch if not
         JSR C30EA3      ; Sound: Cursor
         LDA $28         ; Sell quantity
         CMP #$01        ; One?
         BEQ C3B6E0      ; Abort if so
         DEC $28         ; Quantity -1

; Fork: Sell quantity +10
C3B6A6:  LDA $0B         ; Semi-auto keys
         BIT #$08        ; Pushing up?
         BEQ C3B6C4      ; Branch if not
         JSR C30EA3      ; Sound: Cursor
         LDA #$0A        ; Quantity: 10
         CLC             ; Prepare ADC
         ADC $28         ; Add order size
         CMP $64         ; Owning enough?
         BEQ C3B6BE      ; ...
         BCS C3B6BE      ; Limit if not
         STA $28         ; Set order size
         BRA C3B6E0      ; Handle B

; Fork: Limit sell quantity
C3B6BE:  LDA $64         ; Quantity owned
         STA $28         ; Set order size
         BRA C3B6E0      ; Handle B

; Fork: Sell quantity -10
C3B6C4:  LDA $0B         ; Semi-auto keys
         BIT #$04        ; Pushing down?
         BEQ C3B6E0      ; Branch if not
         JSR C30EA3      ; Sound: Cursor
         LDA $28         ; Sell quantity
         SEC             ; Prepare SBC
         SBC #$0A        ; Subtract 10
         BMI C3B6DC      ; Use 1 if < 0
         CMP #$01        ; Down to zero?
         BCC C3B6E0      ; Abort if so
         STA $28         ; Save changes
         BRA C3B6E0      ; Handle B

; Fork: Set sell quantity to 1
C3B6DC:  LDA #$01        ; Quantity: 1
         STA $28         ; Set order size

; Fork: Handle B
C3B6E0:  LDA $09         ; No-autofire keys
         BIT #$80        ; Pushing B?
         BEQ C3B6FB      ; Branch if not
         JSR C30EA9      ; Sound: Cursor
         LDX $00         ; Clear X
         STX $39         ; BG2 X-Pos: 0
         STX $3B         ; BG2 Y-Pos: 0
         JSR C3B95A      ; Clean up BG3
         LDY #C3C326     ; Text pointer
         JSR C302F9      ; Draw options
         JMP C3B7CF      ; Exit submenu

; Fork: Handle A
C3B6FB:  LDA $08         ; No-autofire keys
         BIT #$80        ; Pushing A?
         BEQ C3B707      ; Exit if not
         JSR C30ECE      ; Sound: Cash
         JSR C3B708      ; ...
C3B707:  RTS             ; ...
C3B708:  JSR C3BB65      ; Get order value
         CLC             ; Prepare ADC
         LDA $1860       ; Gold LB
         ADC $F1         ; Add cost's
         STA $1860       ; Save changes
         REP #$20        ; 16-bit A
         LDA $1861       ; Gold HBs
         ADC $F2         ; Add cost's + C
         STA $1861       ; Save changes
         SEP #$20        ; 8-bit A
         LDA $64         ; Quantity owned
         CMP $28         ; Sold all of it?
         BEQ C3B734      ; Branch if so
         JSR C3BFCB      ; Define Y
         LDA $1969,Y     ; Quantity owned
         SEC             ; Prepare SBC
         SBC $28         ; Deduct qty sold
         STA $1969,Y     ; Save changes
         BRA C3B740      ; Skip 5 lines

; Fork: Clear item slot, leave submenu
C3B734:  JSR C3BFCB      ; Define Y
         LDA #$FF        ; Empty item
         STA $1869,Y     ; Put in slot
         TDC             ; Quantity: 0
         STA $1969,Y     ; Assign to slot
C3B740:  JSR C332CE      ; Cap GP
         LDY #C3C3BD     ; Text pointer
         JSR C302F9      ; Draw "Bye!"
         LDA #$2B        ; C3/B752
         STA $26         ; Next: Exit
         LDA #$20        ; Frames: 32
         STA $20         ; Set delay
         RTS

; 2B: Return to Sell menu after delay
C3B752:  LDA $20         ; Delay expired?
         BNE C3B75F      ; Exit if not
         LDX $00         ; Clear X
         STX $39         ; BG2 X-Pos: 0
         STX $3B         ; BG2 Y-Pos: 0
         JSR C3B7CF      ; Exit submenu
C3B75F:  RTS

; Return to main shop menu
C3B760:  LDA #$C0        ; Scrollbar: Off
         TRB $46         ; Set anim index
         STZ $47         ; Actors: Off
         JSR C3B886      ; Load navig data
         JSR C3B88F      ; Relocate cursor
         JSR C30EFD      ; Set to upload BG1
         JSR C3B94E      ; Clear BG1 maps
         JSR C31368      ; Refresh screen
         JSR C30F39      ; Queue BG3 upload
         JSR C3B95A      ; Clean up BG3
         LDY #C3C326     ; Text pointer
         JSR C302F9      ; Draw options
         LDY #C3C36F     ; Text pointer
         JSR C302F9      ; Draw greeting
         LDY $00         ; Clear Y
         STY $39         ; Reset BG2 X-Pos
         STY $3B         ; Reset BG2 Y-Pos
         LDA #$25        ; C3/B49B
         STA $26         ; Next: Shop menu
         RTS

; Handle selected option in shop menu
C3B792:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C3B79A,X)  ; Handle option

; Jump table
C3B79A:  dw C3B7A3       ; BUY
         dw C3B7C7       ; SELL
         dw C3B7A0       ; EXIT

; Exit shop
C3B7A0:  JMP C3B4B3      ; Queue menu exit

; Initialize Buy menu
C3B7A3:  JSR C3B8A0      ; Load navig data
         JSR C3B8A9      ; Relocate cursor
         LDA #$08        ; Arm waving: On
         TRB $47         ; Never off...
         JSR C3C09A      ; Create actors
         JSR C3C23B      ; Create signs
C3B7B3:  LDY #$0100      ; X: 256
         STY $39         ; Set BG2 X-Pos
         LDY $00         ; Y: 0
         STY $3B         ; Set BG2 Y-Pos
         JSR C3B986      ; Draw all text
         JSR C3BCFD      ; Build sign list
         LDA #$26        ; C3/B4BD
         STA $26         ; Next: Buy list
         RTS

; Initialize Sell menu
C3B7C7:  JSR C30F39      ; Queue BG3 upload
         JSR C3BBE0      ; Cursor/list/bar
         BRA C3B7D2      ; Skip a line

; Return to Sell menu
C3B7CF:  JSR C3BC02      ; Draw list; bar
C3B7D2:  JSR C3B95A      ; Draw title, GP
         LDY #C3C326     ; Text pointer
         JSR C302F9      ; Draw options
         LDY #C3C3A2     ; Text pointer
         JSR C302F9      ; Draw question
         LDA #$29        ; C3/B616
         STA $26         ; Next: Sell list
         RTS

; Invoke buy order menu if justified
C3B7E6:  JSR C3BFC2      ; Selected item
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85000,X   ; Properties
         AND #$07        ; Tool?
         BNE C3B80A      ; Branch if not
         JSR C3BC92      ; Define $64
         LDA $64         ; Owning none?
         BEQ C3B80A      ; Test GP if so
         JSR C30EC0      ; Play buzzer
         LDY #C3C3F5     ; Text pointer
         JSR C302F9      ; Draw excuse
         JMP C3B87D      ; Set to exit

; Fork: Check if enough money
C3B80A:  LDA $1862       ; GP > 65535?
         BNE C3B83E      ; Ample if so
         TDC             ; ...
         LDA $4B         ; Selected slot
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA $7E9F09,X   ; Item's price
         CMP $1860       ; Got as much?
         SEP #$20        ; 8-bit A
         BEQ C3B83E      ; Ample if so
         BCC C3B83E      ; Or if more
         JSR C30EC0      ; Play buzzer
         LDY #C3C3CE     ; Text pointer
         JSR C302F9      ; Draw excuse
         JMP C3B87D      ; Set to exit

; Sub: Define buy quantity limit
C3B82F:  LDA $64         ; Qty in stock
         CLC             ; Prepare ADC
         ADC $65         ; Add qty worn
         STA $69         ; Set total owned
         LDA #$63        ; Quantity: 99
         SEC             ; Prepare SBC
         SBC $69         ; Sub total owned
         STA $6A         ; Set buy limit
         RTS

; Fork: Check if owning 99
C3B83E:  LDA $69         ; Qty owned/worn
         CMP #$63        ; Under 99?
         BCC C3B850      ; Okay if so
         JSR C30EC0      ; Play buzzer
         LDY #C3C3E2     ; Text pointer
         JSR C302F9      ; Draw "Too many!"
         JMP C3B87D      ; Set to exit

; Fork: Can buy item
C3B850:  JSR C30EB2      ; Sound: Click
         LDX #$0008      ; X: 8
         STX $55         ; Set cursor's
         LDX #$0034      ; Y: 52
         STX $57         ; Set cursor's
         LDA #$27        ; C3/B505
         STA $26         ; Next: Order menu
         JSR C3BAA5      ; Draw blue text
         JSR C3BABA      ; Draw item info
         LDY #C3C396     ; Text pointer
         JSR C302F9      ; Draw "How many?"

; Fork: Switch screen
C3B86D:  LDY #$0100      ; Y: 256
         STY $3B         ; Set BG2 Y-Pos
         LDY $00         ; X: 0
         STY $39         ; Set BG2 X-Pos
         JSR C3A796      ; Clear desc GFX
         JSR C3A6F4      ; Build desc map
         RTS

; Set to return to Buy menu after delay
C3B87D:  LDA #$28        ; C3/B60E
         STA $26         ; Next: Exit
         LDA #$20        ; Frames: 32
         STA $20         ; Set delay
         RTS

; Load navigation data for main shop menu
C3B886:  LDY #C3B895     ; C3/B895
         JMP C305FE      ; Load navig data

; Handle D-Pad for main shop menu
C3B88C:  JSR C3072D      ; Handle D-Pad
C3B88F:  LDY #C3B89A     ; C3/B89A
         JMP C30640      ; Relocate cursor

; Navigation data for main shop menu
C3B895:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $03          ; 3 columns
         db $01          ; 1 row

; Cursor positions for main shop menu
C3B89A:  dw $3408        ; BUY
         dw $3430        ; SELL
         dw $3460        ; EXIT

; Load navigation data for Buy menu
C3B8A0:  LDY #C3B8AF     ; C3/B8AF
         JMP C305FE      ; Load navig data

; Handle D-Pad for Buy menu
C3B8A6:  JSR C3072D      ; Handle D-Pad
C3B8A9:  LDY #C3B8B4     ; C3/B8B4
         JMP C30640      ; Relocate cursor

; Navigation data for Buy menu
C3B8AF:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $08          ; 8 rows

; Cursor positions for Buy menu
C3B8B4:  dw $3400        ; Item 1
         dw $4000        ; Item 2
         dw $4C00        ; Item 3
         dw $5800        ; Item 4
         dw $6400        ; Item 5
         dw $7000        ; Item 6
         dw $7C00        ; Item 7
         dw $8800        ; Item 8

; Draw main shop menu and submenu windows, set to update description
C3B8C4:  JSR C36A28      ; Clear BG2 map A
         JSR C36A2D      ; Clear BG2 map B
         JSR C36A32      ; Clear BG2 map C
         LDY #C3BC1B     ; C3/BC1B
         JSR C30341      ; Draw title box A
         LDY #C3BC1F     ; C3/BC1F
         JSR C30341      ; Draw chat box A
         LDY #C3BC23     ; C3/BC23
         JSR C30341      ; Draw option box
         LDY #C3BC27     ; C3/BC27
         JSR C30341      ; Draw GP box
         LDY #C3BC2B     ; C3/BC2B
         JSR C30341      ; Draw item box A
         LDY #C3BC2F     ; C3/BC2F
         JSR C30341      ; Draw title box B
         LDY #C3BC33     ; C3/BC33
         JSR C30341      ; Draw chat box B
         LDY #C3BC3B     ; C3/BC3B
         JSR C30341      ; Draw actor box A
         LDY #C3BC37     ; C3/BC37
         JSR C30341      ; Draw item box B
         LDY #C3BC3F     ; C3/BC3F
         JSR C30341      ; Draw title box C
         LDY #C3BC53     ; C3/BC53
         JSR C30341      ; Draw amounts box
         LDY #C3BC4B     ; C3/BC4B
         JSR C30341      ; Draw desc box
         LDY #C3BC43     ; C3/BC43
         JSR C30341      ; Draw chat box C
         LDY #C3BC4F     ; C3/BC4F
         JSR C30341      ; Draw actor box B
         LDY #C3BC47     ; C3/BC47
         JSR C30341      ; Draw item box C
         JSR C30E52      ; Upload BG2 A+B
         JSR C30E60      ; Upload BG2 C+D
         JSR C3B94E      ; Clear BG1 maps
         JSR C30E28      ; Upload BG1 A+B
         JSR C30E44      ; Upload BG1 C+D...
         JSR C3B95A      ; Draw title, GP
         LDY #C3C326     ; Text pointer
         JSR C302F9      ; Draw options
         LDY #C3C36F     ; Text pointer
         JSR C302F9      ; Draw greeting
         JSR C31B99      ; Queue desc anim
         JSR C30E6E      ; Upload BG3 A+B
         JMP C30E7C      ; Upload BG3 C+D

; Clear BG1 tilemaps (for shop)
C3B94E:  JSR C36A15      ; Clear BG1 map A
         JSR C36A19      ; Clear BG1 map B
         JSR C36A1E      ; Clear BG1 map C
         JMP C36A23      ; Clear BG1 map D

; Draw shop title and party's gold, clear rest of BG3
C3B95A:  JSR C36A3C      ; Clear BG3 map A
         JSR C36A41      ; Clear BG3 map B
         JSR C36A46      ; Clear BG3 map C
         JSR C3BFD3      ; Draw title
         JSR C3C2F7      ; ...
         LDY #C3C338     ; Text pointer
         JSR C302F9      ; Draw "GP"
         JSR C3C2F2      ; Color: User's
         LDY $1860       ; Gold LBs
         STY $F1         ; Memorize it
         LDA $1862       ; Gold HB
         STA $F3         ; Memorize it
         JSR C30582      ; Turn into text
         LDX #$7A33      ; Text position
         JSR C304AC      ; Draw GP total
         RTS

; Draw all text for Buy menu
C3B986:  JSR C3B95A      ; Draw title, GP
         LDY #C3C385     ; Text pointer
         JSR C302F9      ; Draw "Help..."
         JSR C3C2E1      ; Draw Owned, Eqpd
         LDY $00         ; Clear Y
         STY $F1         ; Menu slot: 1
         STZ $E6         ; List size: 0
C3B998:  REP #$20        ; 16-bit A
         LDA $F1         ; Menu slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C3B9FC,X  ; Tilemap ptr
         STA $7E9E89     ; Set position
         LDA $F1         ; Menu slot
         CLC             ; ...
         ADC $67         ; Add shop index
         INC A           ; Skip flags
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDA $C47AC0,X   ; Shop item
         LDX $F1         ; Menu slot
         STA $7E9D89,X   ; Assign item
         CMP #$FF        ; Nothing?
         BEQ C3B9E4      ; Branch if so
         JSR C3C068      ; Load name
         JSR C37FD9      ; Draw name
         LDX $F1         ; Menu slot
         LDA $7E9D89,X   ; Item in slot
         JSR C38321      ; Compute index
         JSR C3BA0C      ; Define price
         JSR C3052E      ; Turn into text
         REP #$20        ; 16-bit A
         LDA $7E9E89     ; Tilemap ptr
         CLC             ; Prepare ADC
         ADC #$001A      ; Skip item name
         TAX             ; Put sum in X
         SEP #$20        ; 8-bit A
         JSR C3049A      ; Draw price
         INC $E6         ; List size +1
C3B9E4:  LDY $F1         ; Menu slot
         INY             ; Menu slot +1
         STY $F1         ; Save changes
         CPY #$0008      ; Done 8 items?
         BNE C3B998      ; Loop if not
         LDA $E6         ; List size
         STA $54         ; Set cursor limit
         JSR C3BC57      ; Get qties owned
         JSR C3BC84      ; Draw qty owned
         JSR C3BCA8      ; Draw qty worn
         RTS

; Tilemap pointers for Buy menu
C3B9FC:  dw $7A0D        ; Item 1
         dw $7A8D        ; Item 2
         dw $7B0D        ; Item 3
         dw $7B8D        ; Item 4
         dw $7C0D        ; Item 5
         dw $7C8D        ; Item 6
         dw $7D0D        ; Item 7
         dw $7D8D        ; Item 8

; Define cost to buy item
C3BA0C:  REP #$20        ; 16-bit A
         LDA $2134       ; Item index
         CLC             ; Prepare ADC
         ADC #$001C      ; Point to price
         TAX             ; Index sum
         LDA $D85000,X   ; Base price
         JSR C3BA2C      ; Apply multiplier
         STA $F3         ; Memorize result
         LDA $F1         ; Menu slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA $F3         ; Modified price
         STA $7E9F09,X   ; Set item price
         SEP #$20        ; 8-bit A
         RTS

; Apply price multiplier for Buy menu
C3BA2C:  PHA             ; Save price
         LDX $67         ; Shop index
         TDC             ; Clear A
         SEP #$20        ; 8-bit A
         LDA $C47AC0,X   ; Shop flags
         AND #$38        ; Get modifier
         REP #$20        ; 16-bit A
         LSR A           ; Put in b2-b4
         LSR A           ; Put in b1-b3
         TAX             ; Index it
         PLA             ; Base price
         JMP (C3BA41,X)  ; Apply modifier

; Jump table for price multipliers
C3BA41:  dw C3BA55       ; 100%
         dw C3BA4F       ; 150%
         dw C3BA56       ; 200%
         dw C3BA58       ; 50%
         dw C3BA5A       ; 50% if female leads, 150% otherwise
         dw C3BA76       ; 50% if male leads, 150% otherwise
         dw C3BA92       ; 50% if Edgar leads

; Increase price by 50% (unused)
C3BA4F:  STA $E7         ; Save price
         LSR A           ; Halve it
         CLC             ; Prepare ADC
         ADC $E7         ; Add base price
C3BA55:  RTS

; Double price (unused)
C3BA56:  ASL A           ; Double price
         RTS

; Halve price
C3BA58:  LSR A           ; Halve price
         RTS

; Halve price if female leads, raise by 50% otherwise (unused)
C3BA5A:  PHA             ; Save price
         SEP #$20        ; 8-bit A
         LDA $0202       ; Leader sprite
         CMP #$06        ; Celes?
         BEQ C3BA71      ; Halve if so
         CMP #$08        ; Relm?
         BEQ C3BA71      ; Halve if so
         CMP #$00        ; Terra?
         BEQ C3BA71      ; Halve if so
         REP #$20        ; 16-bit A
         PLA             ; Base price
         BRA C3BA4F      ; Add 50%
C3BA71:  REP #$20        ; 16-bit A
         PLA             ; Base price
         BRA C3BA58      ; Halve it

; Halve price if male leads, raise by 50% otherwise (unused)
C3BA76:  PHA             ; Save price
         SEP #$20        ; 8-bit A
         LDA $0202       ; Leader sprite
         CMP #$06        ; Celes?
         BEQ C3BA8D      ; +50% if so
         CMP #$08        ; Relm?
         BEQ C3BA8D      ; +50% if so
         CMP #$00        ; Terra?
         BEQ C3BA8D      ; +50% if so
         REP #$20        ; 16-bit A
         PLA             ; Base price
         BRA C3BA58      ; Halve it
C3BA8D:  REP #$20        ; 16-bit A
         PLA             ; Base price
         BRA C3BA4F      ; Add 50%

; Halve price if Edgar leads
C3BA92:  PHA             ; Save price
         SEP #$20        ; 8-bit A
         LDA $0202       ; Leader sprite
         CMP #$04        ; Edgar?
         BEQ C3BAA0      ; Halve if so
         REP #$20        ; 16-bit A
         PLA             ; Base price
         RTS             ; Exit
C3BAA0:  REP #$20        ; 16-bit A
         PLA             ; Base price
         BRA C3BA58      ; Halve it

; Draw blue text for shop order menu, position item name
C3BAA5:  JSR C30F39      ; Queue BG3 upload
         JSR C3B95A      ; Clean up BG3
         JSR C3C2E1      ; Draw Owned, Eqpd
         REP #$20        ; 16-bit A
         LDA #$7A0F      ; Tilemap ptr
         STA $7E9E89     ; Set item position
         SEP #$20        ; 8-bit A
         RTS

; Draw item specs for buy order menu, reset buy quantity
C3BABA:  JSR C3BAEC      ; Draw power info
         JSR C3BC84      ; Draw qty owned
         JSR C3BCA8      ; Draw qty worn
         JSR C3BFC2      ; Selected item
         JSR C3C068      ; Load name
         JSR C37FD9      ; Draw name
         LDA #$01        ; Quantity: 1
         STA $28         ; Set order size
         JMP C3BBAE      ; Draw size, value

; Draw item specs for sell order menu, reset sell quantity
C3BAD3:  JSR C3BC9D      ; Draw qty owned
         JSR C3BF66      ; Draw qty worn
         JSR C3BAF2      ; Draw power info
         JSR C3BFCB      ; Selected item
         JSR C3C068      ; Load name
         JSR C37FD9      ; Draw name
         LDA #$01        ; Quantity: 1
         STA $28         ; Set order size
         JMP C3BBB7      ; Draw size, value

; Draw power-related text for Buy menu
C3BAEC:  JSR C3BFC2      ; Selected item
         JMP C3BAF8      ; Draw power info

; Draw power-related text for Sell menu
C3BAF2:  JSR C3BFCB      ; Selected item
         JMP C3BAF8      ; ...

; Draw power-related text for Buy or Sell menu
C3BAF8:  JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85000,X   ; Properties
         AND #$07        ; Tool?
         BEQ C3BB52      ; Exit if so
         CMP #$06        ; Consumable?
         BEQ C3BB52      ; Exit if so
         CMP #$01        ; Weapon?
         BEQ C3BB30      ; Branch if so
         JSR C3C2F2      ; Color: User's
         LDA $D85014,X   ; Defense
         JSR C304E0      ; Turn into text
         LDX #$7BA9      ; Text position
         JSR C304C0      ; Draw 3 digits
         JSR C3C2F7      ; Color: Blue
         LDY #C3C361     ; Text pointer
         JSR C302F9      ; Draw "Defense"
         LDY #C3C36B     ; Text pointer
         JSR C302F9      ; Draw "…"
         JMP C3C2F2      ; Color: User's

; Fork: Handle weapon
C3BB30:  JSR C3C2F2      ; Color: User's
         LDA $D85014,X   ; Bat.Pwr
         JSR C304E0      ; Turn into text
         LDX #$7BA9      ; Text position
         JSR C304C0      ; Draw 3 digits
         JSR C3C2F7      ; Color: Blue
         LDY #C3C357     ; Text pointer
         JSR C302F9      ; Draw "Bat Pwr"
         LDY #C3C36B     ; Text pointer
         JSR C302F9      ; Draw "…"
         JSR C3C2F2      ; Color: User's
C3BB52:  RTS             ; For Owned, etc.

; Compute buy order value
C3BB53:  TDC             ; Clear A
         LDA $4B         ; Item slot
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA $7E9F09,X   ; Price asked
         STA $F1         ; Memorize it
         SEP #$20        ; 8-bit A
         JMP C3BB81      ; Price x size

; Compute sell order value
C3BB65:  JSR C3BFCB      ; Selected item
         JSR C38321      ; Compute index
         REP #$20        ; 16-bit A
         LDA $2134       ; Load it
         CLC             ; Prepare ADC
         ADC #$001C      ; Point to price
         TAX             ; Index sum
         LDA $D85000,X   ; Base price
         LSR A           ; Halve it
         STA $F1         ; Memorize it
         SEP #$20        ; 8-bit A
         JMP C3BB81      ; ...

; Compute buy or sell order value
C3BB81:  LDA $F1         ; Item value LB
         STA $4202       ; Set multiplicand
         LDA $28         ; Item quantity
         STA $4203       ; Set multiplier
         STZ $EF         ; Product's B3: 0
         NOP
         NOP
         LDX $4216       ; Product
         STX $ED         ; Memorize it
         LDA $F2         ; Item value HB
         STA $4202       ; Set multiplicand
         LDA $28         ; Item quantity
         STA $4203       ; Set multiplier
         REP #$21        ; 16-bit A; C-
         LDA $EE         ; Old product HBs
         ADC $4216       ; Add new product
         STA $F2         ; Set total HBs
         SEP #$20        ; 8-bit A
         LDA $ED         ; Old product LB
         STA $F1         ; Set total LB
         RTS

; Draw buy order size and value
C3BBAE:  JSR C3BBC0      ; Draw order size
         JSR C3BB53      ; Get order value
         JMP C3BBD7      ; Draw order value

; Draw sell order size and value
C3BBB7:  JSR C3BBC0      ; Draw order size
         JSR C3BB65      ; Get order value
         JMP C3BBD7      ; Draw order value

; Draw traded item's quantity and "GP" below
C3BBC0:  JSR C3C2F7      ; Color: Blue
         LDY #C3C33D     ; Text pointer
         JSR C302F9      ; Draw "GP"
         JSR C3C2F2      ; Color: User's
         LDA $28         ; Order size
         JSR C304E0      ; Turn into text
         LDX #$7A2B      ; Text position
         JMP C304B6      ; Draw 2 digits

; Draw order value (held in $F1-$F4)
C3BBD7:  JSR C30582      ; Turn into text
         LDX #$7AA1      ; Text position
         JMP C304AC      ; Draw 7 digits

; Initialize cursor data and draw inventory for Sell menu
C3BBE0:  LDA #$01        ; 64x32 at $0000
         STA $2107       ; Set BG1 map loc
         LDA #$F5        ; Top row: Slot 246
         STA $5C         ; Set scroll limit
         LDA #$0A        ; Onscreen rows: 10
         STA $5A         ; Set rows per page
         LDA #$01        ; Onscreen cols: 1
         STA $5B         ; Set cols per page
         JSR C37D1C      ; Load navig data
         LDY $4D         ; Cursor position
         STY $4F         ; Set as list loc
         LDA $4A         ; Scroll position
         CLC             ; Prepare ADC
         ADC $50         ; Add list V-Slot
         STA $50         ; Set list V-Slot
         JSR C37D25      ; Relocate cursor
C3BC02:  JSR C37E0D      ; Draw inventory
         JSR C3091F      ; Create scrollbar
         REP #$20        ; 16-bit A
         LDA #$0070      ; V-Speed: 0.44 px
         STA $7E354A,X   ; Set scrollbar's
         LDA #$0058      ; Y: 88
         STA $7E34CA,X   ; Set scrollbar's
         SEP #$20        ; 8-bit A
         RTS

; Window layout for Sell menu and main shop menu
C3BC1B:  dw $588B,$0207  ; 09x04 at $588B (Title)
C3BC1F:  dw $589D,$0213  ; 21x04 at $589D (Dialogue)
C3BC23:  dw $598B,$0210  ; 18x04 at $598B (Options)
C3BC27:  dw $59AF,$020A  ; 12x04 at $59AF (GP)
C3BC2B:  dw $5A8B,$101C  ; 30x18 at $5A8B (Items)

; Window layout for Buy menu
C3BC2F:  dw $608B,$0207  ; 09x04 at $608B (Title)
C3BC33:  dw $609D,$0213  ; 21x04 at $609D (Dialogue)
C3BC37:  dw $618B,$0C1C  ; 30x14 at $618B (Items)
C3BC3B:  dw $650B,$061C  ; 30x08 at $650B (Actors)

; Window layout for shop order menus
C3BC3F:  dw $688B,$0207  ; 09x04 at $688B (Title)
C3BC43:  dw $689D,$0213  ; 21x04 at $689D (Dialogue)
C3BC47:  dw $698B,$0711  ; 19x09 at $698B (Item)
C3BC4B:  dw $6BCB,$031C  ; 30x05 at $6BCB (Description)
C3BC4F:  dw $6D0B,$061C  ; 30x08 at $6D0B (Actors)
C3BC53:  dw $69B1,$0709  ; 11x09 at $69B1 (Amounts)

; Compile quantity owned of each item in Buy menu
C3BC57:  LDX #$9DC9      ; 7E/9DC9
         STX $2181       ; Set WRAM LBs
         TDC             ; Clear A
         TAX             ; Menu slot: 1
C3BC5F:  PHX             ; ...
         LDY $00         ; Stock slot: 1
         LDA $7E9D89,X   ; Shop item
C3BC66:  CMP $1869,Y     ; In stock slot?
         BEQ C3BC76      ; Branch if so
         INY             ; Stock slot +1
         CPY #$0100      ; Done all 256?
         BNE C3BC66      ; Loop if not
         STZ $2180       ; Quantity: 0
         BRA C3BC7C      ; Skip 2 lines
C3BC76:  LDA $1969,Y     ; Quantity owned
         STA $2180       ; Set shop item's
C3BC7C:  PLX             ; ...
         INX             ; Menu slot +1
         CPX #$0008      ; Done 8 items?
         BNE C3BC5F      ; Loop if not
         RTS

; Load and draw quantity owned of item in Buy menu
C3BC84:  JSR C3BC92      ; Define $64
C3BC87:  LDA $64         ; Quantity owned
         JSR C304E0      ; Turn into text
         LDX #$7B3F      ; Text position
         JMP C304B6      ; Draw 2 digits

; Get quantity owned of item in Buy menu
C3BC92:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
         TAX             ; Index it
         LDA $7E9DC9,X   ; Quantity owned
         STA $64         ; Set as current
         RTS

; Load and draw quantity owned of item in Sell menu
C3BC9D:  TDC             ; Clear A
         LDA $4B         ; List slot
         TAY             ; Index it
         LDA $1969,Y     ; Item quantity
         STA $64         ; Memorize it
         BRA C3BC87      ; Draw quantity

; Count and draw quantity worn of item in Buy menu
C3BCA8:  JSR C3BFC2      ; Item in slot
         JMP C3BF69      ; Draw quantity

; Get sign found by actor for shop item
C3BCAE:  JSR C3BCC9      ; Actor can use?
         BCC C3BCC7      ; No sign if not
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         REP #$20        ; ...
         ASL A           ; x2
         ASL A           ; x4
         ASL A           ; x8
         ASL A           ; x16
         SEP #$20        ; ...
         CLC             ; ...
         ADC $E0         ; Add char slot
         TAX             ; Index sum
         LDA $7EAA8D,X   ; Sign
         RTS             ; Exit
C3BCC7:  TDC             ; Sign: None
         RTS

; Check whether actor can equip shop item
C3BCC9:  PHB             ; Save DB
         LDA #$00        ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         TDC             ; Clear A
         STA $11D8       ; No Merit Award
         TDC             ; ...
         LDA $E0         ; Char list slot
         TAX             ; Index it
         LDA $7E9E09,X   ; Actor in slot
         JSR C39C48      ; Define compat
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         TAX             ; Index it
         LDA $7E9D89,X   ; Item in slot
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         REP #$20        ; 16-bit A
         LDA $D85001,X   ; Compatibility
         AND $E7         ; Actor can use?
         SEP #$20        ; 8-bit A
         BEQ C3BCFA      ; Branch if not
         PLB             ; Restore DB
         SEC             ; Mark success
         RTS             ; Exit
C3BCFA:  PLB             ; Restore DB
         CLC             ; Mark failure
         RTS

; Build sign list for each item in Buy menu
C3BCFD:  JSR C3BF4F      ; Clear sign list
         LDY #$AA8D      ; 7E/AA8D
         STY $F3         ; Save WRAM adr
         TDC             ; ...
         TAX             ; Item slot: 1
C3BD07:  LDY $F3         ; WRAM address
         STY $2181       ; Set WRAM LBs
         PHX             ; Save item slot
         LDA $7E9D89,X   ; Item in slot
         STA $9F         ; Memorize it
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85014,X   ; Item's power
         STA $9E         ; Memorize it
         LDA $D85000,X   ; Properties
         AND #$07        ; Get class
         CMP #$01        ; Weapon?
         BEQ C3BDA5      ; Branch if so
         CMP #$02        ; Armor?
         BEQ C3BD45      ; Branch if so
         CMP #$03        ; Shield?
         BEQ C3BD3F      ; Branch if so
         CMP #$04        ; Helmet?
         BEQ C3BD42      ; Branch if so
         CMP #$05        ; Relic?
         BEQ C3BD3C      ; Branch if so
         JMP C3BF0A      ; Handle non-gear
C3BD3C:  JMP C3BF18      ; Handle relic
C3BD3F:  JMP C3BE35      ; Handle shield
C3BD42:  JMP C3BEBD      ; Handle helmet

; Fork: Build sign list for armor
C3BD45:  TDC             ; Clear A
         TAX             ; 1st: Terra
C3BD47:  PHX             ; Save actor index
         REP #$20        ; 16-bit A
         LDA $1EDC       ; Shown actors
         AND.L C39C67,X  ; Has our actor?
         BEQ C3BD87      ; Skip if not
         LDA.L C36969,X  ; Actor's address
         TAY             ; Index it
         SEP #$20        ; 8-bit A
         TDC             ; ...
         LDA $0022,Y     ; Actor's armor
         CMP $9F         ; In shop slot?
         BEQ C3BD7E      ; Use "E" if so
         CMP #$FF        ; None?
         BEQ C3BD76      ; Use "^" if so
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85014,X   ; Item's defense
         CMP $9E         ; Matches shop's?
         BEQ C3BD82      ; Use "=" if so
         BCS C3BD7A      ; Use "v" if above
C3BD76:  LDA #$02        ; Sign: "^"
         BRA C3BD84      ; Add to list

; Subfork: Use "v" sign for armor
C3BD7A:  LDA #$03        ; Sign: "v"
         BRA C3BD84      ; Add to list

; Subfork: Use "E" sign for armor
C3BD7E:  LDA #$01        ; Sign: "E"
         BRA C3BD84      ; Skip a line

; Subfork: Use "=" sign for armor
C3BD82:  LDA #$04        ; Sign: "="
C3BD84:  STA $2180       ; Add to list
C3BD87:  PLX             ; Actor index
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0020      ; Done 16 chars?
         BNE C3BD47      ; Loop if not

; Fork: Handle next item
C3BD8F:  REP #$21        ; 16-bit A; C-
         LDA $F3         ; WRAM address
         ADC #$0010      ; Reach next item
         STA $F3         ; Save changes
         SEP #$20        ; 8-bit A
         PLX             ; Item slot
         INX             ; Item slot +1
         CPX #$0008      ; Done 8 items?
         BNE C3BDA2      ; Loop if not
         RTS             ; Exit
C3BDA2:  JMP C3BD07      ; Do next item

; Fork: Build sign list for weapon
C3BDA5:  TDC             ; Clear A
         TAX             ; 1st: Terra
C3BDA7:  PHX             ; Save actor index
         REP #$20        ; 16-bit A
         LDA $1EDC       ; Shown actors
         AND.L C39C67,X  ; Has our actor?
         BEQ C3BE27      ; Skip if not
         LDA.L C36969,X  ; Actor's address
         TAY             ; Index it
         SEP #$20        ; 8-bit A

; Subfork: Check if holding shop item
C3BDBA:  LDA $001F,Y     ; R-Hand item
         CMP $9F         ; In shop slot?
         BEQ C3BE1E      ; Use "E" if so
         LDA $0020,Y     ; L-Hand item
         CMP $9F         ; In shop slot?
         BEQ C3BE1E      ; Use "E" if so

; Subfork: Check if weapon in R-Hand
C3BDC8:  TDC             ; ...
         LDA $001F,Y     ; R-Hand item
         CMP #$FF        ; None?
         BEQ C3BDE0      ; Branch if so
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85000,X   ; Properties
         AND #$07        ; Get class
         CMP #$01        ; Weapon?
         BEQ C3BDFE      ; Branch if so

; Subfork: No weapon in R-Hand, check L-Hand
C3BDE0:  TDC             ; ...
         LDA $0020,Y     ; L-Hand item
         CMP #$FF        ; None?
         BEQ C3BE16      ; Use "^" if so
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85000,X   ; Properties
         AND #$07        ; Get class
         CMP #$01        ; Weapon?
         BNE C3BDFE      ; Branch if not
         TDC             ; ...
         LDA $0020,Y     ; L-Hand item
         BRA C3BE02      ; Compare power

; Subfork: Compare weapons' power
C3BDFE:  TDC             ; ...
         LDA $001F,Y     ; R-Hand item
C3BE02:  CMP #$FF        ; None?
         BEQ C3BE16      ; Use "^" if so
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85014,X   ; Item's Bat.Pwr
         CMP $9E         ; Matches shop's?
         BEQ C3BE22      ; Use "=" if so
         BCS C3BE1A      ; Use "v" if above
C3BE16:  LDA #$02        ; Sign: "^"
         BRA C3BE24      ; Add to list

; Subfork: Use "v" sign for weapon
C3BE1A:  LDA #$03        ; Sign: "v"
         BRA C3BE24      ; Add to list

; Subfork: Use "E" sign for weapon
C3BE1E:  LDA #$01        ; Sign: "E"
         BRA C3BE24      ; Skip a line

; Subfork: Use "=" sign for weapon
C3BE22:  LDA #$04        ; Sign: "="
C3BE24:  STA $2180       ; Add to list
C3BE27:  PLX             ; Actor index
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0020      ; Done 16 chars?
         BNE C3BE32      ; Loop if not
         JMP C3BD8F      ; Do next item
C3BE32:  JMP C3BDA7      ; Do next actor

; Fork: Build sign list for shield
C3BE35:  TDC             ; Clear A
         TAX             ; 1st: Terra
C3BE37:  PHX             ; Save actor index
         REP #$20        ; 16-bit A
         LDA $1EDC       ; Shown actors
         AND.L C39C67,X  ; Has our actor?
         BEQ C3BEAF      ; Skip if not
         LDA.L C36969,X  ; Actor's address
         TAY             ; Index it
         SEP #$20        ; 8-bit A

; Subfork: Check if holding shop item
C3BE4A:  LDA $001F,Y     ; R-Hand item
         CMP $9F         ; In shop slot?
         BEQ C3BEA6      ; Use "E" if so
         LDA $0020,Y     ; L-Hand item
         CMP $9F         ; In shop slot?
         BEQ C3BEA6      ; Use "E" if so

; Subfork: Check if holding a shield
C3BE58:  TDC             ; ...
         LDA $0020,Y     ; L-Hand item...
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85000,X   ; Properties
         AND #$07        ; Get class
         CMP #$03        ; Shield?
         BEQ C3BE86      ; Branch if so
         TDC             ; ...
         LDA $001F,Y     ; R-Hand item
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85000,X   ; Properties
         AND #$07        ; Get class
         CMP #$03        ; Shield?
         BNE C3BE9E      ; Use "^" if not
         TDC             ; ...
         LDA $001F,Y     ; R-Hand item
         BRA C3BE8A      ; Compare defense

; Subfork: Compare shields' defense
C3BE86:  TDC             ; ...
         LDA $0020,Y     ; L-Hand item...
C3BE8A:  CMP #$FF        ; None?...
         BEQ C3BE9E      ; Use "^" if so
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85014,X   ; Item's defense
         CMP $9E         ; Matches shop's?
         BEQ C3BEAA      ; Use "=" if so
         BCS C3BEA2      ; Use "v" if above
C3BE9E:  LDA #$02        ; Sign: "^"
         BRA C3BEAC      ; Add to list

; Subfork: Use "v" sign for shield
C3BEA2:  LDA #$03        ; Sign: "v"
         BRA C3BEAC      ; Add to list

; Subfork: Use "E" sign for shield
C3BEA6:  LDA #$01        ; Sign: "E"
         BRA C3BEAC      ; Skip a line

; Subfork: Use "=" sign for shield
C3BEAA:  LDA #$04        ; Sign: "="
C3BEAC:  STA $2180       ; Add to list
C3BEAF:  PLX             ; Actor index
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0020      ; Done 16 chars?
         BNE C3BEBA      ; Loop if not
         JMP C3BD8F      ; Do next item
C3BEBA:  JMP C3BE37      ; Do next actor

; Fork: Build sign list for helmet
C3BEBD:  TDC             ; Clear A
         TAX             ; 1st: Terra
C3BEBF:  PHX             ; Save char index
         REP #$20        ; 16-bit A
         LDA $1EDC       ; Shown actors
         AND.L C39C67,X  ; Has our actor?
         BEQ C3BEFF      ; Skip if not
         LDA.L C36969,X  ; Actor's address
         TAY             ; Index it
         SEP #$20        ; 8-bit A
         TDC             ; ...
         LDA $0021,Y     ; Actor's helmet
         CMP $9F         ; In shop slot?
         BEQ C3BEF6      ; Use "E" if so
         CMP #$FF        ; None?
         BEQ C3BEEE      ; Use "^" if so
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         LDA $D85014,X   ; Item's defense
         CMP $9E         ; Matches shop's?
         BEQ C3BEFA      ; Use "=" if so
         BCS C3BEF2      ; Use "v" if above
C3BEEE:  LDA #$02        ; Sign: "^"
         BRA C3BEFC      ; Add to list

; Subfork: Use "v" sign for helmet
C3BEF2:  LDA #$03        ; Sign: "v"
         BRA C3BEFC      ; Add to list

; Subfork: Use "E" sign for helmet
C3BEF6:  LDA #$01        ; Sign: "E"
         BRA C3BEFC      ; Skip a line

; Subfork: Use "=" sign for helmet
C3BEFA:  LDA #$04        ; Sign: "="
C3BEFC:  STA $2180       ; Add to list
C3BEFF:  PLX             ; Actor index
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0020      ; Done 16 chars?
         BNE C3BEBF      ; Loop if not
         JMP C3BD8F      ; Do next item

; Fork: Clear sign list for consumable or tool
C3BF0A:  TDC             ; Sign: None
         TAX             ; Actors done: 0
C3BF0C:  STA $2180       ; Add sign to list
         INX             ; Actors done +1
         CPX #$0010      ; Done all 16?
         BNE C3BF0C      ; Loop if not
         JMP C3BD8F      ; Do next item

; Fork: Build sign list for relic
C3BF18:  TDC             ; Clear A
         TAX             ; 1st: Terra
C3BF1A:  PHX             ; Save char index
         REP #$20        ; 16-bit A
         LDA $1EDC       ; Shown actors
         AND.L C39C67,X  ; Has our actor?
         BEQ C3BF44      ; Skip if not
         LDA.L C36969,X  ; Actor's address
         TAY             ; Index it
         SEP #$20        ; 8-bit A
         TDC             ; ...
         LDA $0023,Y     ; Actor relic 1
         CMP $9F         ; In shop slot?
         BEQ C3BF3F      ; Use "E" if so
         LDA $0024,Y     ; Actor relic 2
         CMP $9F         ; In shop slot?
         BEQ C3BF3F      ; Use "E" if so
         TDC             ; Sign: None
         BRA C3BF41      ; Skip a line
C3BF3F:  LDA #$01        ; Sign: "E"
C3BF41:  STA $2180       ; Add to list
C3BF44:  PLX             ; Actor index
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0020      ; Done 16 chars?
         BNE C3BF1A      ; Loop if not
         JMP C3BD8F      ; Do next item

; Clear sign list for every item in Buy menu (16 actors per item)
C3BF4F:  PHB             ; Save DB
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         TDC             ; Clear A
         TAX             ; Index: 0
         REP #$20        ; 16-bit A
C3BF58:  STZ $AA8D,X     ; Clear 2 signs
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0080      ; Done 8 items?
         BNE C3BF58      ; Loop if not
         SEP #$20        ; 8-bit A
         PLB             ; Restore DB
         RTS

; Count and draw quantity worn of item in Sell menu
C3BF66:  JSR C3BFCB      ; Selected item
C3BF69:  STA $E0         ; Memorize it
         STZ $65         ; Quantity worn: 0
         LDX #$161F      ; 00/161F
         STX $E7         ; Set address LBs
         LDA #$00        ; Bank: 00
         STA $E9         ; Set address HB
         LDX $00         ; 1st: Terra
C3BF78:  PHX             ; Save actor slot
         REP #$20        ; 16-bit A
         TXA             ; Get actor
         ASL A           ; Double it
         TAX             ; Index it
         LDA $1EDC       ; Eligible actors
         AND.L C39C67,X  ; Has our actor?
         BEQ C3BFA5      ; Skip if not
         LDA.L C36969,X  ; Actor's address
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDA $0000,X     ; Actor
         CMP #$0E        ; Guest?
         BCS C3BFA5      ; Skip if so
         LDY $00         ; 1st: R-Hand
C3BF97:  LDA [$E7],Y     ; Equipped item
         CMP $E0         ; Matches shop's?
         BNE C3BF9F      ; Branch if not
         INC $65         ; Quantity worn +1
C3BF9F:  INY             ; Gear slot +1
         CPY #$0006      ; Done all 6?
         BNE C3BF97      ; Loop if not
C3BFA5:  REP #$21        ; 16-bit A; C-
         LDA #$0025      ; Actor data size
         ADC $E7         ; Add SRAM pointer
         STA $E7         ; Set SRAM pointer
         SEP #$20        ; 8-bit A
         PLX             ; Actor slot
         INX             ; Point to next
         CPX #$0010      ; Done all 16?
         BNE C3BF78      ; Loop if not
         LDA $65         ; Quantity worn
         JSR C304E0      ; Turn into text
         LDX #$7C3F      ; Text position
         JMP C304B6      ; Draw 2 digits

; Get item by cursor in Buy menu
C3BFC2:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
         TAX             ; Index it
         LDA $7E9D89,X   ; Item in slot
         RTS

; Get item selected in Sell menu
C3BFCB:  TDC             ; Clear A
         LDA $4B         ; List slot
         TAY             ; Index it
         LDA $1869,Y     ; Item in slot
         RTS

; Draw shop title and define shop index
C3BFD3:  JSR C3C2F7      ; Color: Blue
C3BFD6:  LDA $4212       ; PPU status
         AND #$40        ; H-Blank?
         BEQ C3BFD6      ; Loop if not
         LDA $0201       ; Shop number
         STA $211B       ; Set matrix A LB
         STZ $211B       ; Clear HB
         LDA #$09        ; Shop data size
         STA $211C       ; Set matrix B
         STA $211C       ; ...
         LDX $2134       ; Index product
         STX $67         ; Set shop index
         LDA $C47AC0,X   ; Shop flags
         AND #$07        ; Title number
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C3C00C,X  ; Text pointer
         STA $E7         ; Set src LBs
         SEP #$20        ; 8-bit A
         LDA #$C3        ; Bank: C3
         STA $E9         ; Set src HB
         JMP C302FF      ; Draw title

; Pointers to shop titles
C3C00C:  dw C30000       ; Bogus...
         dw C3C2FC       ; Weapon
         dw C3C305       ; Armor
         dw C3C30D       ; Item
         dw C3C314       ; Relics
         dw C3C31D       ; Vendor

; Set to condense BG3 text in shop menu
C3C018:  LDA #$02        ; 1Rx2B to PPU
         STA $4350       ; Set DMA mode
         LDA #$12        ; $2112
         STA $4351       ; To BG3 V-Scroll
         LDY #C3C037     ; C3/C037
         STY $4352       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4354       ; Set src HB
         LDA #$C3        ; ...
         STA $4357       ; Set indir HB
         LDA #$20        ; Channel: 5
         TSB $43         ; Queue HDMA-5
         RTS

; BG3 text shifting table for shop
C3C037:  db $2F,$04,$00  ; Title
         db $0C,$04,$00  ; Item 1
         db $0C,$08,$00  ; Item 2
         db $0C,$0C,$00  ; Item 3
         db $0C,$10,$00  ; Item 4
         db $0C,$14,$00  ; Item 5
         db $0C,$18,$00  ; Item 6
         db $0C,$1C,$00  ; Item 7
         db $0C,$20,$00  ; Item 8
         db $0C,$24,$00  ; Nothing
         db $0C,$28,$00  ; Nothing
         db $0C,$2C,$00  ; Nothing
         db $0C,$30,$00  ; Nothing
         db $0C,$34,$00  ; Nothing
         db $0C,$38,$00  ; Nothing
         db $0C,$3C,$00  ; Nothing
         db $00          ; End

; Load item's name
C3C068:  PHA             ; Save item
         LDX #$9E8B      ; 7E/9E8B
         STX $2181       ; Set WRAM LBs
C3C06F:  LDA $4212       ; PPU status
         AND #$40        ; H-Blank?
         BEQ C3C06F      ; Loop if not
         PLA             ; Item
         STA $211B       ; Set matrix A LB
         STZ $211B       ; Clear HB
         LDA #$0D        ; Name data size
         STA $211C       ; Set matrix B
         STA $211C       ; ...
         LDX $2134       ; Index product
         LDY #$000D      ; Letters: 13
C3C08B:  LDA $D2B300,X   ; Letter
         STA $2180       ; Add to string
         INX             ; Point to next
         DEY             ; One less left
         BNE C3C08B      ; Loop till last
         STZ $2180       ; End string
         RTS

; Compile and create actors for Buy menu
C3C09A:  JSR C3C109      ; Compile actors
         JSR C3C1CC      ; Mark members
         TDC             ; Clear A
         TAX             ; List slot: 1
C3C0A2:  LDA $7E9E09,X   ; Actor in slot
         BMI C3C0EC      ; Exit if none
         PHX             ; Save slot
         PHA             ; Save actor
         LDA #$02        ; Min slot: 16
         LDY #C3C141     ; C3/C141
         JSR C31173      ; Queue OAM fn
         TXY             ; Queue slot
         TDC             ; Clear A
         PLA             ; Actor
         STA $7E35C9,X   ; Link to OBJ
         ASL A           ; Double it
         TAX             ; Index it
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         REP #$20        ; 16-bit A
         LDA $D8E917,X   ; Anim table ptr
         STA $32C9,Y     ; Set sprite's
         SEP #$20        ; 8-bit A
         PLX             ; List slot
         LDA.L C3C0ED,X  ; X position
         STA $33CA,Y     ; Set actor's
         LDA.L C3C0FB,X  ; Y position
         STA $344A,Y     ; Set actor's
         TDC             ; ...
         STA $33CB,Y     ; No use...
         STA $344B,Y     ; No use...
         LDA #$D8        ; Bank: D8
         STA $35CA,Y     ; Set ptr HB
         LDA #$00        ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         INX             ; List slot +1
         BRA C3C0A2      ; Do next char
C3C0EC:  RTS

; X positions for shop actors
C3C0ED:  db $18          ; Actor 1
         db $38          ; Actor 2
         db $58          ; Actor 3
         db $78          ; Actor 4
         db $98          ; Actor 5
         db $B8          ; Actor 6
         db $D8          ; Actor 7
         db $18          ; Actor 8
         db $38          ; Actor 9
         db $58          ; Actor 10
         db $78          ; Actor 11
         db $98          ; Actor 12
         db $B8          ; Actor 13
         db $D8          ; Actor 14

; Y positions for shop actors
C3C0FB:  db $9C          ; Actor 1
         db $9C          ; Actor 2
         db $9C          ; Actor 3
         db $9C          ; Actor 4
         db $9C          ; Actor 5
         db $9C          ; Actor 6
         db $9C          ; Actor 7
         db $B8          ; Actor 8
         db $B8          ; Actor 9
         db $B8          ; Actor 10
         db $B8          ; Actor 11
         db $B8          ; Actor 12
         db $B8          ; Actor 13
         db $B8          ; Actor 14

; Compile actors for Buy menu
C3C109:  LDX #$9E09      ; 7E/9E09
         STX $2181       ; Set WRAM LBs
         LDX $00         ; 1st: Terra
C3C111:  PHX             ; Save char slot
         REP #$20        ; 16-bit A
         TXA             ; Actor slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA $1EDC       ; Showable chars
         AND.L C39C67,X  ; Has our actor?
         BEQ C3C132      ; Skip if not
         LDA.L C36969,X  ; Actor's address
         TAY             ; Index it
         TDC             ; Clear A
         SEP #$20        ; 8-bit A
         LDA $0000,Y     ; Actor
         CMP #$0E        ; Guest?
         BCS C3C132      ; Skip if so
         STA $2180       ; Add to list
C3C132:  SEP #$20        ; 8-bit A
         PLX             ; Actor slot
         INX             ; Slot +1
         CPX #$0010      ; Done all 16?
         BNE C3C111      ; Loop if not
         LDA #$FF        ; Terminator
         STA $2180       ; End list
         RTS

; Update shop actor
C3C141:  TAX             ; Index mode
         JMP (C3C145,X)  ; Handle mode

; Jump table for the above
C3C145:  dw C3C149       ; Initialize data
         dw C3C16A       ; Sustain sprite

; Mode 0: Initialize data
C3C149:  LDA #$01        ; Hide actors: N
         TSB $47         ; Set menu flag
         LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         REP #$20        ; 16-bit A
         LDA $32C9,X     ; Anim table ptr
         STA $34CA,X     ; Save original
         SEP #$20        ; 8-bit A
         JSR C31206      ; Set pose timer
         LDA $47         ; Menu flags
         AND #$08        ; Shop mode?...
         BNE C3C168      ; Branch if not
         JSR C3C1F0      ; Create big arrow
C3C168:  BRA C3C16A      ; ...

; Mode 1: Sustain sprite
C3C16A:  LDA $47         ; Menu flags
         AND #$01        ; Remove actors?
         BEQ C3C19A      ; Delete if so
         LDX $2D         ; Queue index
         LDA $47         ; Menu flags
         AND #$08        ; Shop mode?...
         BNE C3C189      ; Branch if not
         JSR C3C19C      ; Waving arms?
         BCC C3C189      ; Branch if not
         LDX $2D         ; Queue index
         REP #$21        ; 16-bit A; C-
         LDA $34CA,X     ; Base anim ptr
         ADC #$0009      ; Adjust value
         BRA C3C190      ; Set real ptr
C3C189:  LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         LDA $34CA,X     ; Base anim ptr
C3C190:  STA $32C9,X     ; Set as current
         SEP #$20        ; ...
         JSR C31221      ; Define OAM
         SEC             ; Set to requeue
         RTS             ; Exit
C3C19A:  CLC             ; Set to dequeue
         RTS

; Determine whether shop actor should wave its arms
C3C19C:  PHB             ; Save DB
         LDA #$00        ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         TDC             ; Clear A
         STA $11D8       ; No Merit Award
         LDA $7E35C9,X   ; Actor
         JSR C39C48      ; Define compat
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         TAX             ; Index it
         LDA $7E9D89,X   ; Item in slot
         JSR C38321      ; Compute index
         LDX $2134       ; Load it
         REP #$20        ; 16-bit A
         LDA $D85001,X   ; Compatibility
         AND $E7         ; Actor can use?
         SEP #$20        ; 8-bit A
         BEQ C3C1C9      ; Fail if not
         PLB             ; Restore DB
         SEC             ; Mark success
         RTS             ; Exit
C3C1C9:  PLB             ; Restore DB
         CLC             ; Mark failure
         RTS

; Compile party members for Buy menu
C3C1CC:  LDX #$9E01      ; 7E/9E01
         STX $2181       ; Set WRAM LBs
         LDX $00         ; Member index: 0
C3C1D4:  REP #$20        ; 16-bit A
         LDA $006D,X     ; Actor's address
         SEP #$20        ; 8-bit A
         BEQ C3C1E3      ; Skip if nobody
         TAY             ; Index it
         LDA $0000,Y     ; Actor in slot
         BRA C3C1E5      ; Skip a line
C3C1E3:  LDA #$FF        ; Actor: None
C3C1E5:  STA $2180       ; Add to list
         INX             ; Member index +1
         INX             ; Member index +1
         CPX #$0008      ; Done 4 members?
         BNE C3C1D4      ; Loop if not
         RTS

; Create arrow under shop actor if in party
C3C1F0:  LDY $00         ; Member slot: 1
         LDX $2D         ; Queue index
C3C1F4:  LDA $35C9,X     ; Shop actor
         CMP $9E01,Y     ; In member slot?
         BNE C3C234      ; Try next if not
         PHX             ; Save queue index
         PHY             ; Save member slot
         LDA #$00        ; ...
         PHA             ; ...
         PLB             ; ...
         LDA #$00        ; Min slot: 0
         LDY #C37B42     ; C3/7B42
         JSR C31173      ; Queue OAM fn
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         TDC             ; Clear A
         STA $35C9,X     ; No use...
         LDY $374A,X     ; Actor's index
         REP #$20        ; 16-bit A
         LDA $33CA,Y     ; Actor's X
         STA $33CA,X     ; Set arrow's
         LDA $344A,Y     ; Actor's Y
         DEC A           ; +1 px up
         DEC A           ; +1 px up
         STA $344A,X     ; Set arrow's Y
         LDA #$EBA9      ; Anim table ptr
         STA $32C9,X     ; Set arrow's
         SEP #$20        ; 8-bit A
         LDA #$D8        ; Bank: D8
         STA $35CA,X     ; Set ptr HB
         PLY             ; Member slot
         PLX             ; Queue index
C3C234:  INY             ; Member slot +1
         CPY #$0004      ; Done all 4?
         BNE C3C1F4      ; Loop if not
         RTS

; Create sign by each actor in Buy menu
C3C23B:  TDC             ; Clear A
         TAY             ; Char slot: 1
C3C23D:  PHY             ; Save char slot
         LDA #$04        ; Min slot: 32
         LDY #C3C253     ; C3/C253
         JSR C31173      ; Queue OAM fn
         PLY             ; Char slot
         TYA             ; Put in A
         STA $7E35C9,X   ; Assign to sign
         INY             ; Char slot +1
         CPY #$000E      ; Done all 14?
         BNE C3C23D      ; Loop if not
         RTS

; Update shop sign
C3C253:  TAX             ; Index mode
         JMP (C3C257,X)  ; Handle mode

; Jump table for the above
C3C257:  dw C3C25B       ; Initialize sprite
         dw C3C28B       ; Sustain sprite

; Mode 0: Initialize sprite
C3C25B:  LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         LDA #$EBCD      ; Anim table ptr
         STA $32C9,X     ; Set current
         STA $34CA,X     ; Set original
         SEP #$20        ; 8-bit A
         INC $3649,X     ; Mode +1
         LDA #$D8        ; Bank: D8
         STA $35CA,X     ; Set ptr HB
         TDC             ; Clear A
         LDA $35C9,X     ; Char slot
         TXY             ; Queue index
         TAX             ; Index slot
         LDA $D8EBB1,X   ; X position
         STA $33CA,Y     ; Set sign's
         LDA $D8EBBF,X   ; Y position
         STA $344A,Y     ; Set sign's
         LDX $2D         ; Queue index
         JSR C31206      ; Set pose timer

; Mode 1: Sustain sprite
C3C28B:  LDA $47         ; Menu flags
         AND #$01        ; Actors shown?
         BEQ C3C2DF      ; Delete if not
         LDX $2D         ; Queue index
         TDC             ; ...
         LDA $35C9,X     ; Char slot
         STA $E0         ; Memorize it
         JSR C3BCAE      ; Sign
         BEQ C3C2DD      ; Exit if none
         CMP #$01        ; Equipped?
         BEQ C3C2B6      ; Branch if so
         CMP #$02        ; Up?
         BEQ C3C2CB      ; Branch if so
         CMP #$04        ; Equal?
         BEQ C3C2BF      ; Branch if so

; Fork: Down sign
C3C2AA:  LDX $2D         ; Queue index
         REP #$21        ; 16-bit A; C-
         LDA $34CA,X     ; Base anim ptr
         ADC #$0018      ; Adjust value
         BRA C3C2D5      ; Set real ptr

; Fork: Equipped sign
C3C2B6:  LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         LDA $34CA,X     ; Base anim ptr
         BRA C3C2D5      ; Set as current

; Fork: Equal sign
C3C2BF:  LDX $2D         ; Queue index
         REP #$21        ; 16-bit A; C-
         LDA $34CA,X     ; Base anim ptr
         ADC #$0024      ; Adjust value
         BRA C3C2D5      ; Set real ptr

; Fork: Up sign
C3C2CB:  LDX $2D         ; Queue index
         REP #$21        ; 16-bit A; C-
         LDA $34CA,X     ; Base anim ptr
         ADC #$000C      ; Adjust value
C3C2D5:  STA $32C9,X     ; Set real ptr
         SEP #$20        ; ...
         JSR C31221      ; Define OAM
C3C2DD:  SEC             ; Set to requeue
         RTS

; Fork: Delete sign
C3C2DF:  CLC             ; Set to dequeue
         RTS

; Draw "Owned:" and "Equipped:" for Buy menu
C3C2E1:  JSR C3C2F7      ; Color: Blue
         LDY #C3C342     ; Text pointer
         JSR C302F9      ; Draw "Owned:"
         LDY #C3C34B     ; Text pointer
         JSR C302F9      ; Draw "Equipped:"
         BRA C3C2F2      ; ...

; Set text color to player's color
C3C2F2:  LDA #$20        ; Palette 0
         STA $29         ; Color: User's
         RTS

; Set text color to blue
C3C2F7:  LDA #$2C        ; Palette 3
         STA $29         ; Color: Blue
         RTS

; Positioned text for shop menu
C3C2FC:  dw $790D : db "Weapon",$00
C3C305:  dw $790F : db "Armor",$00
C3C30D:  dw $790F : db "Item",$00
C3C314:  dw $790D : db "Relics",$00
C3C31D:  dw $790D : db "Vendor",$00
C3C326:  dw $7A0F : db "BUY  SELL  EXIT",$00
C3C338:  dw $7A41 : db "GP",$00
C3C33D:  dw $7B2B : db "GP",$00
C3C342:  dw $7AB3 : db "Owned:",$00
C3C34B:  dw $7BB3 : db "Equipped:",$00
C3C357:  dw $7B8F : db "Bat Pwr",$00
C3C361:  dw $7B8F : db "Defense",$00
C3C36B:  dw $7BA5 : db "…",$00
C3C36F:  dw $791F : db "Hi! Can I help you?",$00
C3C385:  dw $791F : db "Help yourself!",$00
C3C396:  dw $791F : db "How many?",$00
C3C3A2:  dw $791F : db "Whatcha got?",$00
C3C3B1:  dw $791F : db "How many?",$00
C3C3BD:  dw $791F : db "Bye!          ",$00
C3C3CE:  dw $791F : db "You need more GP!",$00
C3C3E2:  dw $791F : db "Too many!       ",$00
C3C3F5:  dw $791F : db "One's plenty! ",$00

; =============================================================================

; Jump table for ending sequences
C3C406:  dw C3C5BE       ; 00: Fade screen before ending scene
         dw C3C5D4       ; 01: Return to event script
         dw C3C869       ; 02: Show aerial-view panning clouds
         dw C3C8A6       ; 03: Wait before fading screen
         dw C3C8AD       ; 04: Show spinning clouds
         dw C3C5E1       ; 05: Start sideview airship scene
         dw C3C681       ; 06: Bogus...
         dw C3C6DC       ; 07: Bogus...
         dw C3C6DC       ; 08: Bogus...
         dw C3C794       ; 09: Start aerial-view airship scene
         dw C3C7D2       ; 0A: Show aerial-view airship
         dw C3C7E1       ; 0B: Fade screen to white
         dw C3C8D1       ; 0C: Start boat scene
         dw C3C917       ; 0D: Show boat sprite
         dw C3C9CD       ; 0E: Bogus...
         dw C3C9CD       ; 0F: Bogus...
         dw C3C9CD       ; 10: Start skimming airship scene
         dw C3CA8C       ; 11: Show swooping bird
         dw C3CABE       ; 12: Unused...
         dw C3CABE       ; 13: Unused...
         dw C3CD17       ; 14: Start frontview airship scene
         dw C3CDA0       ; 15: Show late bird flock
         dw C3CDEA       ; 16: Bogus...
         dw C3CDEA       ; 17: Bogus...
         dw C3CEA6       ; 18: Start aerial-view plains scene
         dw C3CEEC       ; 19: Bogus...
         dw C3CEEC       ; 1A: Bogus...
         dw C3CEEC       ; 1B: Bogus...
         dw C3CEEC       ; 1C: Start rearview airship scene
         dw C3D018       ; 1D: Bogus...
         dw C3D018       ; 1E: Bogus...
         dw C3D018       ; 1F: Bogus...
         dw C3D02F       ; 20: Start final airship scene
         dw C3D096       ; 21: Fade final airship
         dw C3D122       ; 22: Bogus...
         dw C3D122       ; 23: Bogus...
         dw C3D122       ; 24: Bogus...
         dw C3C794       ; 25: Bogus...
         dw C3C794       ; 26: Bogus...
         dw C3C794       ; 27: Bogus...
         dw C3E26E       ; 28: Start Shadow's scene
         dw C3E2B2       ; 29: Fade in "Shadow as"
         dw C3E2C1       ; 2A: Switch Shadow's names
         dw C3E2D0       ; 2B: Fade all but Shadow's name
         dw C3C794       ; 2C: Bogus...
         dw C3E6CE       ; 2D: Start first book scene
         dw C3E6DF       ; 2E: Animate first book
         dw C3E6EE       ; 2F: Wait 480 frames
         dw C3E6FA       ; 30: Pixelate and fade first book
         dw C3C794       ; 31: Bogus...
         dw C3E2F8       ; 32: Start Cyan's scene
         dw C3E319       ; 33: Fade in "Cyan as"
         dw C3E328       ; 34: Switch Cyan's names
         dw C3E337       ; 35: Fade all but Cyan's name
         dw C3C794       ; 36: Bogus...
         dw C3C794       ; 37: Bogus...
         dw C3E2E7       ; 38: Fade actor's true name
         dw C3C794       ; 39: Bogus...
         dw C3C794       ; 3A: Bogus...
         dw C3C794       ; 3B: Bogus...
         dw C3E3E1       ; 3C: Start Mog's scene
         dw C3E3FD       ; 3D: Fade in "Mog as"
         dw C3E40C       ; 3E: Switch Mog's names
         dw C3E41B       ; 3F: Fade all but Mog's name
         dw C3E34B       ; 40: Start Edgar and Sabin's scene
         dw C3E364       ; 41: Fade in "Edgar as"
         dw C3E373       ; 42: Switch Edgar's names
         dw C3E382       ; 43: Show Sabin's name, fade Edgar's
         dw C3E3A2       ; 44: Delete Edgar's name
         dw C3E3B2       ; 45: Switch Sabin's names
         dw C3E432       ; 46: Start Gogo's scene
         dw C3E459       ; 47: Fade in "Gogo as"
         dw C3E47C       ; 48: Switch Gogo's names
         dw C3E48B       ; 49: Fade all but Gogo's name
         dw C3E711       ; 4A: Start last book scene
         dw C3E72A       ; 4B: Wait 180 frames
         dw C3E736       ; 4C: Stop last book and fade in text
         dw C3E749       ; 4D: Pixelate and fade last book
         dw C3C794       ; 4E: Bogus...
         dw C3E3CD       ; 4F: Fade all but Sabin's name
         dw C3E4FA       ; 50: Start Gau's scene
         dw C3E513       ; 51: Fade in "Gau as"
         dw C3E522       ; 52: Switch Gau's names; create face
         dw C3E534       ; 53: Fade all but Gau's name
         dw C3C794       ; 54: Bogus...
         dw C3C794       ; 55: Bogus...
         dw C3C794       ; 56: Bogus...
         dw C3C794       ; 57: Bogus...
         dw C3C794       ; 58: Bogus...
         dw C3C794       ; 59: Bogus...
         dw C3E54B       ; 5A: Start Terra's scene
         dw C3E564       ; 5B: Fade in "Terra as"
         dw C3E573       ; 5C: Switch Terra's names, create glint
         dw C3E585       ; 5D: Fade all but Terra's name
         dw C3C794       ; 5E: Bogus...
         dw C3C794       ; 5F: Bogus...
         dw C3C794       ; 60: Bogus...
         dw C3C794       ; 61: Bogus...
         dw C3C794       ; 62: Bogus...
         dw C3C794       ; 63: Bogus...
         dw C3E59C       ; 64: Start Locke and Celes's scene
         dw C3E5B7       ; 65: Fade in "Locke as"
         dw C3E5C6       ; 66: Switch Locke's names
         dw C3E5D5       ; 67: Show Celes's name, fade Locke's
         dw C3E5F5       ; 68: Delete Locke's name
         dw C3E605       ; 69: Switch Celes's names
         dw C3E61E       ; 6A: Fade all but Celes's name
         dw C3C794       ; 6B: Bogus...
         dw C3C794       ; 6C: Bogus...
         dw C3C794       ; 6D: Bogus...
         dw C3E635       ; 6E: Start Relm's scene
         dw C3E651       ; 6F: Fade in "Relm as"
         dw C3E660       ; 70: Switch Relm's names
         dw C3E66F       ; 71: Fade all but Relm's name
         dw C3C794       ; 72: Bogus...
         dw C3C794       ; 73: Bogus...
         dw C3C794       ; 74: Bogus...
         dw C3C794       ; 75: Bogus...
         dw C3C794       ; 76: Bogus...
         dw C3C794       ; 77: Bogus...
         dw C3E686       ; 78: Start Strago's scene
         dw C3E69C       ; 79: Fade in "Strago as"
         dw C3E6AB       ; 7A: Switch Strago's names
         dw C3E6BA       ; 7B: Fade all but Strago's name
         dw C3C794       ; 7C: Bogus...
         dw C3C794       ; 7D: Bogus...
         dw C3C794       ; 7E: Bogus...
         dw C3C794       ; 7F: Bogus...
         dw C3C794       ; 80: Bogus...
         dw C3C794       ; 81: Bogus...
         dw C3E75D       ; 82: Start Setzer's scene
         dw C3E794       ; 83: Fade in "Setzer as"
         dw C3E7A3       ; 84: Switch Setzer's names
         dw C3E7B2       ; 85: Fade background
         dw C3E7C1       ; 86: Fade cards and name
         dw C3E7E5       ; 87: Start Umaro's scene
         dw C3E804       ; 88: Fade in "Umaro as"
         dw C3E813       ; 89: Switch Umaro's names
         dw C3E822       ; 8A: Fade all but Umaro's name

; Display requested ending cinematic
C3C51C:  PHP             ; Push PS
         REP #$30        ; 16-bit A, X, Y
         PHA             ; ...
         PHX             ; ...
         PHY             ; Push Y
         PHB             ; Push DB
         PHD             ; Push DP
         SEP #$20        ; 8-bit A
         LDA #$00        ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         LDX #$0000      ; Clear X
         PHX             ; Put on stack
         PLD             ; Set DP to 0
         LDX #$0000      ; ...
         STX $00         ; ...
         LDA #$7E        ; Bank: 7E
         STA $2183       ; Set WRAM HB
         JSR C300C0      ; Reroute NMI/IRQ
         JSR C368FA      ; Reset variables
         LDY #$012C      ; Scroll delay: 300
         STY $85         ; For true char name
         STZ $B4         ; Blue credits: N
         JSR C3C586      ; Stop VRAM DMA
         JSR C3C576      ; Disable pad, etc.
         JSL $D4CD48     ; Init registers
         JSL C3A424      ; Init joypad...
         JSR C31114      ; Reset OAM, queue
         JSR C3DD73      ; Clear VRAM
         JSL $D4CF3B     ; Back up data
         LDA $0201       ; Event parameter
         STA $26         ; Set scene mode
         JSR C3C5A5      ; Handle scene
         JSL $D4CF4B     ; Restore backup
         JSR C3C576      ; Disable pad, etc.
         REP #$30        ; 16-bit A, X, Y
         PLD             ; Pull DP
         PLB             ; Pull DB
         PLY             ; Pull Y
         PLX             ; ...
         PLA             ; ...
         PLP             ; Pull PS
         RTL

; Disable screen, interrupts, joypad, and HDMA
C3C576:  LDA #$8F        ; BRT: 15 and OFF
         STA $2100       ; Disable screen
         TDC             ; Clear A
         STA $4200       ; Disable INT, pad
         STA $420B       ; Disable DMA...
         STA $420C       ; Disable HDMA
         RTS

; Reset variables for automatic uploads during NMI
C3C586:  TDC             ; Clear A
         TAY             ; Clear Y
         STY $1B         ; Halt VRAM B
         STY $1D         ; Clear src-B LBs
         STA $1F         ; Clear src-B HB
         STY $16         ; Clear src-A LBs
         STA $18         ; Clear src-A HB
         LDY #$0001      ; Bytes: 1
         STY $19         ; Set data size B
         STY $12         ; Set data size A
         LDY #$7FFF      ; $FFFE
         STY $14         ; Set VRAM ptr A
         RTS

; Enable color addition on BG1
C3C59F:  LDA #$01        ; BG1: ADD mode
         STA $2131       ; Set register
         RTS

; Handle ending sequence
C3C5A5:  TDC             ; Clear A
         LDA $26         ; Scene mode
         CMP #$FF        ; Exit to map?
         BEQ C3C5BD      ; Exit if so
         REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         JSR (C3C406,X)  ; Handle mode
         JSR C311B0      ; Run anim queue
         JSR C31368      ; Refresh screen
         BRA C3C5A5      ; Loop
C3C5BD:  RTS

; 00: Fade screen before ending scene
C3C5BE:  LDY $20         ; Delay expired?
         BNE C3C5D3      ; Exit if not
         LDA #$01        ; C3/C5D4
         STA $26         ; Next: Exit
         LDY #$000F      ; Frames: 15
         STY $20         ; Set exit delay
         LDA #$00        ; Min slot: 0
         LDY #C3D1FD     ; C3/D1FD
         JSR C31173      ; Queue fade-out
C3C5D3:  RTS

; 01: Return to event script after delay
C3C5D4:  LDY $20         ; Delay expired?
         BNE C3C5DB      ; Exit if not
         JMP C3E269      ; End scene
C3C5DB:  RTS

; Set text for credits to be blue
C3C5DC:  LDA #$01        ; Blue text: Y
         STA $B4         ; Set color mode
         RTS

; 05: Start sideview airship scene
C3C5E1:  JSR C3C5DC      ; Blue text: Y
         JSL $D4CED7     ; Init registers
         JSR C3D40C      ; Upload GFX, map
         JSR C3D3E6      ; Reset M7 vars
         JSL $D4CBFC     ; Queue HDMA 1-7
         LDY #$0010      ; Zoom-out: 16
         STY $8E         ; Set for airship
         REP #$20        ; 16-bit A
         LDA #$FFF1      ; H-Scroll: -15
         STA $7EB68D     ; Set for airship
         LDA #$002E      ; V-Scroll: 46
         STA $7EB68F     ; Set for airship
         LDA #$0071      ; Center X: 113
         STA $7EB695     ; Set for airship
         LDA #$008D      ; Center Y: 141
         STA $7EB697     ; Set for airship
         SEP #$20        ; 8-bit A
         LDY #$005E      ; Vertical angle
         STY $C7         ; Set for clouds
         LDY #$2F00      ; Base divisor
         STY $C5         ; Set matrices'
         LDY #$0100      ; Center X: 256
         STY $B7         ; Set for clouds
         LDY #$0311      ; Center Y: 785
         STY $B9         ; Set for clouds
         LDY #$0080      ; BG1's X: 128
         STY $35         ; Set for clouds
         LDY #$0291      ; BG1's Y: 657
         STY $37         ; Set for clouds
         JSR C3DDD2      ; Make matrix tbl
         LDY $00         ; Scene timer: 0
         STY $CF         ; Set for text
         JSR C3D96D      ; Build text OAM
         LDA #$02        ; Min slot: 16
         LDY #C3D7B9     ; C3/D7B9
         JSR C31173      ; Queue credits
         LDA #$02        ; Min slot: 16
         LDY #C3C681     ; C3/C681
         JSR C31173      ; Queue M7 anim
         LDA #$00        ; Min slot: 0
         LDY #C3D0F2     ; C3/D0F2
         JSR C31173      ; Queue rotor anim
         JSR C3D15C      ; Make text black
         JSR C3D173      ; Load cloud colors
         JSR C3D018      ; Load sky/plane's
         LDA #$03        ; C3/C8A6
         STA $26         ; Next: Fade-out
         LDY #$021C      ; Frames: 540
         STY $20         ; Set fade delay
         JMP C3C66C      ; ...

; Queue field fade-in
C3C66C:  LDA #$00        ; Min slot: 0
         LDY #C3D1CC     ; C3/D1CC
         JSR C31173      ; Queue fade-in
         RTS

; Set brightness before fading in colors manually
C3C675:  LDA #$01        ; BRT: 1 and ON
         STA $44         ; Set brightness
         JSR C31368      ; Refresh screen
         LDA #$0F        ; BRT: 15 and ON
         STA $44         ; Set brightness
         RTS

; Shrink sideview airship and scroll clouds
C3C681:  TAX             ; Index mode
         JMP (C3C685,X)  ; Handle mode

; Jump table for the above
C3C685:  dw C3C68B       ; Initialize unused timer
         dw C3C69A       ; Shrink airship, scroll clouds
         dw C3C6BA       ; Scroll clouds

; Mode 0: Initialize unused timer...
C3C68B:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         REP #$20        ; 16-bit A
         LDA #$024E      ; Frames: 590
         STA $3349,X     ; Set mode timer
         SEP #$20        ; 8-bit A

; Mode 1: Shrink airship, scroll clouds
C3C69A:  LDX $2D         ; Queue index
         LDA $23         ; NMI count
         AND #$01        ; Odd value?
         BNE C3C6A6      ; Branch if so
         REP #$20        ; 16-bit A
         INC $8E         ; Matrix A +1
C3C6A6:  REP #$20        ; 16-bit A
         LDA $8E         ; Matrix A
         STA $0600       ; Set for airship
         STZ $07C2       ; Matrix B: 0
         STZ $0984       ; Matrix C: 0
         JSR C3C6BF      ; Scroll clouds
         SEP #$20        ; ...
         SEC             ; Set to requeue
         RTS

; Mode 2: Scroll clouds (unused)
C3C6BA:  JSR C3C6BF      ; Scroll clouds
         SEC             ; Set to requeue
         RTS

; Scroll clouds under sideview airship
C3C6BF:  REP #$20        ; 16-bit A
         DEC $35         ; BG1's X -1
         DEC $B7         ; Center X -1
         LDA $35         ; BG1 X-Pos
         STA $B691       ; To HDMA table
         LDA $37         ; BG1 Y-Pos
         STA $B693       ; To HDMA table
         LDA $B7         ; Center X
         STA $B699       ; To HDMA table
         LDA $B9         ; Center Y
         STA $B69B       ; To HDMA table
         SEP #$20        ; 8-bit A
         RTS

; Set to fade credits
C3C6DC:  LDA #$C3        ; C3/10F4
         STA $ED         ; Set src HB
         LDA #$04        ; Slowness: 4
         LDY #$31C9      ; To OBJ pal 4
         STY $E7         ; ...
         LDX #C310F4     ; Black palette
         STX $EB         ; ...
         JSR C30FAA      ; Do big font
         LDA #$C3        ; ...
         STA $ED         ; ...
         LDA #$04        ; Slowness: 4
         LDY #$31E9      ; To OBJ pal 5
         STY $E7         ; ...
         LDX #C310F4     ; Black palette
         STX $EB         ; ...
         JSR C30FAA      ; Do small font
         RTS

; Set to fade in credits to white and blue
C3C703:  LDA #$C2        ; Bank: C2
         STA $ED         ; Set src HB
         LDA #$04        ; Slowness: 4
         LDY #$31C9      ; To OBJ pal 4
         STY $E7         ; ...
         LDX #$9754      ; C2/9754
         STX $EB         ; ...
         JSR C30FAA      ; Do big font
         LDA #$C2        ; ...
         STA $ED         ; ...
         LDA #$04        ; Slowness: 4
         LDY #$31E9      ; To OBJ pal 5
         STY $E7         ; ...
         LDX #$974C      ; C2/974C
         STX $EB         ; ...
         JSR C30FAA      ; Do small font
         RTS

; Set to fade in credits to dark blue
C3C72A:  LDA #$C2        ; Bank: C2
         STA $ED         ; Set src HB
         LDA #$04        ; Slowness: 4
         LDY #$31C9      ; To OBJ pal 4
         STY $E7         ; ...
         LDX #$9744      ; C2/9744
         STX $EB         ; ...
         JSR C30FAA      ; Do big font
         LDA #$C2        ; ...
         STA $ED         ; ...
         LDA #$04        ; Slowness: 4
         LDY #$31E9      ; To OBJ pal 5
         STY $E7         ; ...
         LDX #$973C      ; C2/973C
         STX $EB         ; ...
         JSR C30FAA      ; Do small font
         RTS

; Load non-text sprite colors for Mode 7 scene
C3C751:  LDA #$C2        ; Source HB
         LDY #$3149      ; To OBJ pal 0
         LDX #$97F4      ; Source LBs
         JSR C30F8E      ; Do balloon's
         LDA #$C2        ; Source HB
         LDY #$3169      ; To OBJ pal 1
         LDX #$9794      ; Source LBs
         JSR C30F8E      ; Do airships'
         LDA #$C2        ; Source HB
         LDY #$3189      ; To OBJ pal 2
         LDX #$97B4      ; Source LBs
         JSR C30F8E      ; Do boat's
         LDA #$C2        ; Source HB
         LDY #$31A9      ; To OBJ pal 3
         LDX #$97D4      ; Source LBs
         JSR C30F8E      ; Do cockpit's
         LDA #$C2        ; Source HB
         LDY #$3209      ; To OBJ pal 6
         LDX #$9834      ; Source LBs
         JSR C30F8E      ; Do gray birds'
         LDA #$C2        ; Source HB
         LDY #$3229      ; To OBJ pal 7
         LDX #$9814      ; Source LBs
         JSR C30F8E      ; Do spray's
         RTS

; 09: Start aerial-view airship scene
C3C794:  JSR C3C5DC      ; Blue text: Y
         JSL $D4CED7     ; Init registers
         JSR C3D522      ; Upload GFX, map
         JSR C3D3E6      ; Reset M7 vars
         JSL $D4CB8F     ; HDMA: Matrices
         JSR C3C751      ; Load OBJ colors
         JSR C3D15C      ; Make text black
         JSR C3D173      ; Load cloud colors
         LDY #$8A70      ; Anim ptr LBs
         LDA #$C2        ; Anim ptr HB
         JSR C3D225      ; Queue cloud anim
         JSR C3D983      ; Build text OAM
         LDY $00         ; Scene timer: 0
         STY $CF         ; Set for text
         LDA #$02        ; Min slot: 16
         LDY #C3D7CB     ; C3/D7CB
         JSR C31173      ; Queue credits
         JSR C3D2A0      ; Queue M7 handler
         INC $26         ; Next: C3/C7D2
         LDY #$03C0      ; Frames: 960
         STY $20         ; Set plane delay
         JMP C3C66C      ; Queue fade-in

; 0A: Show aerial-view airship and its shadow
C3C7D2:  LDY $20         ; Delay expired?
         BNE C3C7E0      ; Exit if not
         INC $26         ; Next: C3/C7E1
         LDY #$0870      ; Frames: 2160
         STY $20         ; Set fade delay
         JSR C3C802      ; Create sprites
C3C7E0:  RTS

; 0B: Fade screen to white
C3C7E1:  LDY $20         ; Delay expired?
         BNE C3C801      ; Exit if not
         LDA #$03        ; C3/C8A6
         STA $26         ; Next: Black out
         LDY #$0078      ; Frames: 120
         STY $20         ; Set fade delay
         LDA #$C3        ; Bank: C3
         STA $ED         ; Set src HB
         LDA #$02        ; Slowness: 2
         LDY #$30A9      ; To BG pal 3
         STY $E7         ; ...
         LDX #C310D4     ; White palette
         STX $EB         ; ...
         JSR C30FAA      ; Whiten clouds
C3C801:  RTS

; Create aerial-view airship and its shadow
C3C802:  JSR C3C846      ; Queue ship fn
         REP #$20        ; 16-bit A
         LDA #$8CDC      ; Ship anim ptr
         JSR C3C84F      ; Set spd, timer
         SEP #$20        ; 8-bit A
         LDA #$C2        ; Bank: C2
         STA $7E35CA,X   ; Set ptr HB
         LDA #$F8        ; X: 248
         STA $7E33CA,X   ; Set airship's
         LDA #$A0        ; Y: 160
         STA $7E344A,X   ; Set airship's
         LDA #$03        ; Min slot: 24
         LDY #C3DE84     ; C3/DE84
         JSR C31173      ; Queue shadow fn
         REP #$20        ; 16-bit A
         LDA #$8CF0      ; Shadow anim ptr
         JSR C3C84F      ; Set spd, timer
         SEP #$20        ; 8-bit A
         LDA #$C2        ; Bank: C2
         STA $7E35CA,X   ; Set ptr HB
         LDA #$F8        ; X: 248
         STA $7E33CA,X   ; Set shadow's
         LDA #$B0        ; Y: 176
         STA $7E344A,X   ; Set shadow's
         RTS

; Queue linearly moving temporary sprite
C3C846:  LDA #$01        ; Min slot: 8
         LDY #C3DE84     ; C3/DE84
         JSR C31173      ; Queue OAM fn
         RTS

; Initialize data for aerial-view airship or its shadow
C3C84F:  STA $7E32C9,X   ; Set anim ptr
         LDA #$FFC0      ; H-Spd: -0.25 px
         STA $7E34C9,X   ; Set sprite's
         LDA #$FFE0      ; V-Spd: -0.125 px
         STA $7E3549,X   ; Set sprite's
         LDA #$0400      ; Frames: 1024
         STA $7E3349,X   ; Set hide delay
         RTS

; 02: Show aerial-view panning clouds
C3C869:  JSR C3C87E      ; Load map, etc.
         LDY #$00F0      ; Frames: 240
         STY $20         ; Set fade delay
         LDY #$8B3C      ; Anim ptr LBs
         LDA #$C2        ; Anim ptr HB
         JSR C3D225      ; Queue cloud anim
         INC $26         ; Next: Fade-out
         JMP C3C66C      ; Queue fade-in

; Initialize data for spinning or panning clouds
C3C87E:  JSL $D4CED7     ; Init registers
         JSR C3D522      ; Upload GFX, map
         JSR C3D3E6      ; Reset M7 vars
         JSL $D4CB8F     ; HDMA: Matrices
         JSR C3C751      ; Load OBJ colors
         JSR C3D15C      ; Make text black
         LDY #$0200      ; Vertical angle
         STY $C7         ; Set for clouds
         LDY #$F000      ; Base divisor
         STY $C5         ; Set matrices'
         JSR C3DDD2      ; Make matrix tbl
         JSR C3D173      ; Load cloud colors
         JSR C3D2A0      ; Queue M7 handler
         RTS

; 03: Wait before fading screen
C3C8A6:  LDY $20         ; Delay expired?
         BNE C3C8AC      ; Exit if not
         STZ $26         ; Next: Fade-out
C3C8AC:  RTS

; 04: Show spinning clouds
C3C8AD:  JSR C3C87E      ; Load map, etc.
         LDY #$8000      ; Vertical angle
         STY $C7         ; Set for clouds
         LDY #$8000      ; Base divisor
         STY $C5         ; Set matrices'
         JSR C3DDD2      ; Make matrix tbl
         LDY #$0078      ; Frames: 120
         STY $20         ; Set fade delay
         LDY #$8B42      ; Anim ptr LBs
         LDA #$C2        ; Anim ptr HB
         JSR C3D225      ; Queue cloud anim
         LDA #$03        ; C3/C8A6
         STA $26         ; Next: Fade-out
         JMP C3C66C      ; Queue fade-in

; 0C: Start boat scene
C3C8D1:  JSL $D4CED7     ; Init registers
         JSR C3C59F      ; Color math: BG1
         JSR C3D5AA      ; Upload GFX, map
         JSR C3D3E6      ; Reset M7 vars
         JSL $D4CB8F     ; HDMA: Matrices
         LDY #$1000      ; Base divisor
         STY $C5         ; Set matrices'
         JSR C3D15C      ; Make text black
         JSR C3D173      ; Load BG1 colors
         JSR C3C751      ; Load OBJ colors
         LDY #$8AD9      ; Anim ptr LBs
         LDA #$C2        ; Anim ptr HB
         JSR C3D225      ; Queue sea anim
         JSR C3CAC7      ; Create birds
         JSR C3D999      ; Build text OAM
         LDY $00         ; Scene timer: 0
         STY $CF         ; Set for text
         LDA #$02        ; Min slot: 16
         LDY #C3D819     ; C3/D819
         JSR C31173      ; Queue credits
         JSR C3D2A0      ; Queue M7 handler
         LDY #$0438      ; Delay: 1080
         STY $20         ; Set boat OBJ's
         INC $26         ; Next: C3/C917
         JMP C3C66C      ; Queue fade-in

; 0D: Show boat sprite
C3C917:  LDY $20         ; Delay expired?
         BNE C3C925      ; Exit if not
         JSR C3C94E      ; Create boat
         STZ $26         ; Next: Fade-out
         LDY #$02D0      ; Frames: 720
         STY $20         ; Set fade delay
C3C925:  RTS

; Create boat sprite (unused)
C3C926:  JSR C3E9D2      ; Queue OAM fn
         REP #$20        ; 16-bit A
         LDA #$F7FD      ; Anim table ptr
         STA $7E32C9,X   ; Set sprite's
         LDA #$FFC0      ; H-Spd: -0.25 px
         STA $7E34C9,X   ; Set sprite's
         SEP #$20        ; 8-bit A
         LDA #$CF        ; Bank: CF
         STA $7E35CA,X   ; Set ptr HB
         LDA #$F8        ; X: 248
         STA $7E33CA,X   ; Set sprite's
         LDA #$70        ; Y: 112
         STA $7E344A,X   ; Set sprite's
         RTS

; Create boat sprite
C3C94E:  JSR C3E9D2      ; Queue L-Half
         REP #$20        ; 16-bit A
         LDA #$F809      ; Anim table ptr
         STA $7E32C9,X   ; Set L-Half's
         LDA #$FFC0      ; H-Spd: -0.25 px
         STA $7E34C9,X   ; Set L-Half's
         SEP #$20        ; 8-bit A
         LDA #$CF        ; Bank: CF
         STA $7E35CA,X   ; Set ptr HB
         LDA #$F8        ; X: 248
         STA $7E33CA,X   ; Set L-Half's
         LDA #$50        ; Y: 80
         STA $7E344A,X   ; Set L-Half's
         LDA #$01        ; Min slot: 8
         LDY #C3C9A2     ; C3/C9A2
         JSR C31173      ; Queue R-Half
         REP #$20        ; 16-bit A
         LDA #$F7FD      ; Anim table ptr
         STA $7E32C9,X   ; Set R-Half's
         LDA #$FFC0      ; H-Spd: -0.25 px
         STA $7E34C9,X   ; Set R-Half's
         SEP #$20        ; 8-bit A
         LDA #$CF        ; Bank: CF
         STA $7E35CA,X   ; Set ptr HB
         LDA #$F8        ; X: 248
         STA $7E33CA,X   ; Set R-Half's
         LDA #$50        ; Y: 80
         STA $7E344A,X   ; Set R-Half's
         RTS

; Animate boat's right half
C3C9A2:  TAX             ; Index mode
         JMP (C3C9A6,X)  ; Handle mode

; Jump table for the above
C3C9A6:  dw C3C9AA       ; Initialize timers
         dw C3C9BC       ; Sustain sprite

; Mode 0: Initialize timers
C3C9AA:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         REP #$20        ; 16-bit A
         LDA #$0040      ; Frames: 64
         STA $3349,X     ; Set show delay
         SEP #$20        ; 8-bit A
         JSR C31206      ; Set pose timer

; Mode 1: Sustain sprite
C3C9BC:  LDX $2D         ; Queue index
         LDY $3349,X     ; Delay expired?
         BNE C3C9C8      ; Branch if not
         JSR C3DEC0      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS             ; Exit
C3C9C8:  JSR C3CFE5      ; Delay -1
         SEC             ; Set to requeue
         RTS

; 10: Start skimming airship scene
C3C9CD:  JSL $D4CED7     ; Init registers
         JSR C3C59F      ; Color math: BG1
         JSR C3D5DA      ; Upload GFX, map
         JSR C3CA71      ; Get sky; init M7
         JSR C3D38C      ; Queue gradient
         JSR C3D36F      ; HDMA: Color math
         JSR C3C751      ; Load OBJ colors
         LDY #$0028      ; Y: 40
         STY $3B         ; Set BG2 Y-Pos
         LDY #$FF6D      ; Mod index: 109
         STY $C3         ; Set matrices'
         LDY #$034C      ; Vertical angle
         STY $C7         ; Set for sea
         LDY #$FD00      ; Base divisor
         STY $C5         ; Set matrices'
         JSR C3DDD2      ; Make matrix tbl
         JSR C3CAFD      ; Create birds
         LDA #$02        ; Min slot: 16
         LDY #C3CBC6     ; C3/CBC6
         JSR C31173      ; Queue airship
         REP #$20        ; 16-bit A
         LDA #$8BB1      ; Anim table ptr
         STA $7E32C9,X   ; Set airship's
         SEP #$20        ; 8-bit A
         LDA #$C2        ; Bank: C2
         STA $7E35CA,X   ; Set ptr HB
         LDA #$78        ; X: 120
         STA $7E33CA,X   ; C3/CBDB...
         LDA #$58        ; Base Y/2: 88
         STA $7E344A,X   ; C3/CBE0...
         JSR C3E9D2      ; Queue shadow
         REP #$20        ; 16-bit A
         LDA #$8BEC      ; Anim table ptr
         STA $7E32C9,X   ; Set shadow's
         SEP #$20        ; 8-bit A
         LDA #$C2        ; Bank: C2
         STA $7E35CA,X   ; Set ptr HB
         LDA #$80        ; X: 128
         STA $7E33CA,X   ; Set shadow's
         LDA #$80        ; Y: 128
         STA $7E344A,X   ; Set shadow's
         JSR C3D173      ; Load sea colors
         JSR C3D9AF      ; Build text OAM
         LDY $00         ; Scene timer: 0
         STY $CF         ; Set for text
         LDA #$02        ; Min slot: 16
         LDY #C3D849     ; C3/D849
         JSR C31173      ; Queue credits
         LDY #$8B36      ; Anim ptr LBs
         LDA #$C2        ; Anim ptr HB
         JSR C3D225      ; Queue sea anim
         LDA #$03        ; Min slot: 24
         LDY #C3CAA2     ; C3/CAA2
         JSR C31173      ; Set to pan sky
         JSR C3D2A0      ; Queue M7 handler
         INC $26         ; Next: Late bird
         LDY #$04B0      ; Frames: 1200
         STY $20         ; Set bird's delay
         JMP C3C66C      ; Queue fade-in

; Load cloudy sky graphics data, exclude sky from Mode 7
C3CA71:  JSR C3D3E6      ; Reset M7 vars
         JSR C3D4D3      ; Load GFX, map
         JSR C3D34B      ; Set up M7 HDMA
         JSR C3D15C      ; Make text black
         JMP C3CA80      ; ...
C3CA80:  LDA #$C2        ; Source HB
         LDY #$3049      ; To BG pal 0
         LDX #$953C      ; Source LBs
         JSR C30F8E      ; Load sky colors
         RTS

; 11: Show swooping bird
C3CA8C:  LDY $20         ; Delay expired?
         BNE C3CAA1      ; Exit if not
         LDA #$03        ; C3/C8A6
         STA $26         ; Next: Fade-out
         LDY #$0708      ; Frames: 1800
         STY $20         ; Set fade delay
         LDA #$01        ; Min slot: 8
         LDY #C3CC79     ; C3/CC79
         JSR C31173      ; Queue bird OAM
C3CAA1:  RTS

; Scroll sky eastward
C3CAA2:  LDA $23         ; NMI count
         AND #$01        ; Odd value?
         BNE C3CAAE      ; Exit if so
         REP #$20        ; 16-bit A
         DEC $39         ; BG2 camera -1
         SEP #$20        ; 8-bit A
C3CAAE:  SEC             ; Set to requeue
         RTS

; Scroll sky westward
C3CAB0:  LDA $23         ; NMI count
         AND #$01        ; Odd value?
         BNE C3CABC      ; Exit if so
         REP #$20        ; 16-bit A
         INC $39         ; BG2 camera +1
         SEP #$20        ; 8-bit A
C3CABC:  SEC             ; Set to requeue
         RTS

; 12-13: Return to event script after delay (unused variant)
C3CABE:  LDY $20         ; Delay expired?
         BNE C3CAC6      ; Exit if not
         LDA #$FF        ; Null value
         STA $26         ; Next: Exit
C3CAC6:  RTS

; Create birds for boat scene
C3CAC7:  LDX $00         ; ROM index: 0
C3CAC9:  PHX             ; Save ROM index
         JSR C3CB5F      ; Queue anim fn
         TXY             ; Queue index
         PLX             ; ROM index
         PHB             ; Save DB
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         REP #$20        ; 16-bit A
         LDA $CFF7B5,X   ; Anim table ptr
         INX             ; ROM index +1
         INX             ; ROM index +1
         STA $32C9,Y     ; Set bird's
         SEP #$20        ; 8-bit A
         LDA $CFF7B5,X   ; Base X / 2
         INX             ; ROM index +1
         STA $34CA,Y     ; Set bird's
         LDA $CFF7B5,X   ; Base Y
         INX             ; ROM index +1
         STA $344A,Y     ; Set bird's
         LDA #$01        ; Pans with BG1
         STA $364A,Y     ; Set OBJ flags
         PLB             ; Restore DB
         CPX #$0018      ; Done 6 birds?
         BNE C3CAC9      ; Loop if not
         RTS

; Create oscillating birds around skimming airship
C3CAFD:  LDX $00         ; ROM index: 0
C3CAFF:  PHX             ; Save ROM index
         JSR C3CB5F      ; Queue anim fn
         TXY             ; Queue index
         PLX             ; ROM index
         PHB             ; Save DB
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         REP #$20        ; 16-bit A
         LDA $CFF7CD,X   ; Anim table ptr
         INX             ; ROM index +1
         INX             ; ROM index +1
         STA $32C9,Y     ; Set bird's
         SEP #$20        ; 8-bit A
         LDA $CFF7CD,X   ; Base X / 2
         INX             ; ROM index +1
         STA $34CA,Y     ; Set bird's
         LDA $CFF7CD,X   ; Base Y
         INX             ; ROM index +1
         STA $344A,Y     ; Set bird's
         PLB             ; Restore DB
         CPX #$0018      ; Done 6 birds?
         BNE C3CAFF      ; Loop if not
         RTS

; Create birds above grassfield
C3CB2E:  LDX $00         ; ROM index: 0
C3CB30:  PHX             ; Save ROM index
         JSR C3CB5F      ; Queue anim fn
         TXY             ; Queue index
         PLX             ; ROM index
         PHB             ; Save DB
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         REP #$20        ; 16-bit A
         LDA $CFF7E5,X   ; Anim table ptr
         INX             ; ROM index +1
         INX             ; ROM index +1
         STA $32C9,Y     ; Set bird's
         SEP #$20        ; 8-bit A
         LDA $CFF7E5,X   ; Base X / 2
         INX             ; ROM index +1
         STA $34CA,Y     ; Set bird's
         LDA $CFF7E5,X   ; Base Y
         INX             ; ROM index +1
         STA $344A,Y     ; Set bird's
         PLB             ; Restore DB
         CPX #$0018      ; Done 6 birds?
         BNE C3CB30      ; Loop if not
         RTS

; Queue oscillating bird
C3CB5F:  LDA #$02        ; Min slot: 16
         LDY #C3CB68     ; C3/CB68
         JSR C31173      ; Queue anim fn
         RTS

; Animate oscillating bird
C3CB68:  TAX             ; Index mode
         JMP (C3CB6C,X)  ; Handle mode

; Jump table for the above
C3CB6C:  dw C3CB70       ; Initialize data
         dw C3CB87       ; Sustain sprite

; Mode 0: Initialize data
C3CB70:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         STZ $334A,X     ; X-Mod index HB
         LDA.L C3CB68,X  ; X-Mod index LB
         STA $3349,X     ; Set bird's
         LDA #$CF        ; Bank: CF
         STA $35CA,X     ; Set ptr HB
         JSR C31206      ; Set pose timer

; Mode 1: Sustain sprite
C3CB87:  LDX $2D         ; Queue index
         JSR C3CB94      ; Init X position
         INC $3349,X     ; X-Mod index +1
         JSR C3DEC0      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS

; Update bird's back-and-forth motion (range: -8 to +7)
C3CB94:  REP #$20        ; 16-bit A
         LDA $3349,X     ; X-Mod index
         JSR C3DE76      ; Fract X mod
         STA $EB         ; Set original
         STA $E0         ; Set current
         LDA $E0         ; Shift right?
         BPL C3CBA8      ; Branch if so
         EOR #$FFFF      ; Invert value
         INC A           ; Add 1
C3CBA8:  STA $E0         ; Save changes
         LDA $EB         ; Shift right?
         BPL C3CBB7      ; Branch if so
         JSR C3CC31      ; Modifier / 16
         EOR #$FFFF      ; Invert value
         INC A           ; Add 1
         BRA C3CBBA      ; Skip a line
C3CBB7:  JSR C3CC31      ; Modifier / 16
C3CBBA:  LDX $2D         ; Queue index
         CLC             ; Prepare ADC
         ADC $34C9,X     ; Add base X/2
         STA $33C9,X     ; Init bird's X
         SEP #$20        ; 8-bit A
         RTS

; Animate skimming airship
C3CBC6:  TAX             ; Index mode
         JMP (C3CBCA,X)  ; Handle mode

; Jump table
C3CBCA:  dw C3CBCE       ; Initialize data
         dw C3CBE6       ; Sustain sprite

; Mode 0: Initialize data
C3CBCE:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         STZ $334A,X     ; Anim timer HB
         STZ $3349,X     ; Anim timer LB
         LDA #$78        ; X: 120
         STA $33CA,X     ; Set sprite's
         LDA #$20        ; Base Y/2: 32
         STA $354A,X     ; Set sprite's
         JSR C31206      ; Set pose timer

; Mode 1: Sustain sprite
C3CBE6:  LDX $2D         ; Queue index
         JSR C3CBFF      ; Init Y position
         LDX $2D         ; Queue index
         INC $3349,X     ; Anim timer +1
         LDA $3349,X     ; Anim timer
         CMP #$38        ; Within 56-255?
         BCS C3CBFA      ; Branch if so
         JSR C3CC38      ; Create spray
C3CBFA:  JSR C3DEC0      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS

; Update airship's up-and-down motion (range: -8 to +7)
C3CBFF:  REP #$20        ; 16-bit A
         LDA $3349,X     ; Anim timer
         JSR C3DE7A      ; Fract Y mod
         STA $EB         ; Set original
         STA $E0         ; Set current
         LDA $E0         ; Shift down?
         BPL C3CC13      ; Branch if so
         EOR #$FFFF      ; Invert value
         INC A           ; Add 1
C3CC13:  STA $E0         ; Save changes
         LDA $EB         ; Shift down?
         BPL C3CC22      ; Branch if so
         JSR C3CC31      ; Modifier / 16
         EOR #$FFFF      ; Invert value
         INC A           ; Add 1
         BRA C3CC25      ; Skip a line
C3CC22:  JSR C3CC31      ; Modifier / 16
C3CC25:  LDX $2D         ; Queue index
         CLC             ; Prepare ADC
         ADC $3549,X     ; Add base Y
         STA $3449,X     ; Init ship's Y
         SEP #$20        ; 8-bit A
         RTS

; Divide sprite's position modifier by 16
C3CC31:  LDA $E0         ; Y modifier
         LSR A           ; ÷2
         LSR A           ; ÷4
         LSR A           ; ÷8
         LSR A           ; ÷16
         RTS

; Create water spray
C3CC38:  LDA $23         ; NMI count
         AND #$03        ; Now 0-3
         BNE C3CC78      ; Exit if 1-3
         PHB             ; Save DB
         LDA #$00        ; ...
         PHA             ; ...
         PLB             ; ...
         JSR C3C846      ; Queue anim fn
         REP #$20        ; 16-bit A
         LDA #$8D0B      ; Anim table ptr
         STA $7E32C9,X   ; Set sprite's
         LDA #$0100      ; H-Spd: +1 px
         STA $7E34C9,X   ; Set sprite's
         LDA #$FF80      ; V-Spd: -0.5 px
         STA $7E3549,X   ; Set sprite's
         SEP #$20        ; 8-bit A
         LDA #$18        ; Frames: 24
         STA $7E3349,X   ; Set hide delay
         LDA #$C2        ; Bank: C2
         STA $7E35CA,X   ; Set ptr HB
         LDA #$7E        ; X: 126
         STA $7E33CA,X   ; Set sprite's
         LDA #$7C        ; Y: 124
         STA $7E344A,X   ; Set sprite's
         PLB             ; Restore DB
C3CC78:  RTS

; Animate swooping bird
C3CC79:  TAX             ; Index mode
         JMP (C3CC7D,X)  ; Handle mode

; Jump table for the above
C3CC7D:  dw C3CC81       ; Initialize sprite
         dw C3CCA8       ; Sustain sprite

; Mode 0: Initialize sprite
C3CC81:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         LDA #$CF        ; Anim ptr HB
         STA $35CA,X     ; Set sprite's
         REP #$20        ; 16-bit A
         LDA #$F772      ; Anim ptr LBs
         STA $32C9,X     ; Set sprite's
         LDA #$0010      ; Pos index: 16
         STA $3349,X     ; Set sprite's
         SEP #$20        ; 8-bit A
         LDA #$00        ; Base X HB: 0
         STA $34CA,X     ; Set sprite's
         LDA #$00        ; Base Y HB: 0
         STA $354A,X     ; Set sprite's
         JSR C31206      ; Set pose timer

; Mode 1: Sustain sprite
C3CCA8:  LDX $2D         ; Queue index
         LDA $33CA,X     ; X position
         CMP #$08        ; Under 8?
         BCS C3CCB3      ; Display if not
         CLC             ; Set to dequeue
         RTS

; Fork: Set X position
C3CCB3:  REP #$20        ; 16-bit A
         LDA $3349,X     ; Position index
         JSR C3DE76      ; Fractional X
         STA $EB         ; ...
         STA $E0         ; ...
         LDA $E0         ; ...
         BPL C3CCC7      ; ...
         EOR #$FFFF      ; ...
         INC A           ; ...
C3CCC7:  STA $E0         ; ...
         LDA $EB         ; ...
         BPL C3CCD6      ; ...
         LDA $E0         ; ...
         ASL A           ; ...
         EOR #$FFFF      ; ...
         INC A           ; ...
         BRA C3CCD9      ; ...
C3CCD6:  LDA $E0         ; ...
         ASL A           ; Double it
C3CCD9:  LDX $2D         ; Queue index
         CLC             ; Prepare ADC
         ADC $34C9,X     ; Add base X
         STA $33C9,X     ; Set bird's X

; Fork: Set Y position
C3CCE2:  LDA $3349,X     ; Position index
         JSR C3DE7A      ; Fractional Y
         STA $EB         ; ...
         STA $E0         ; ...
         LDA $E0         ; ...
         BPL C3CCF4      ; ...
         EOR #$FFFF      ; ...
         INC A           ; ...
C3CCF4:  STA $E0         ; ...
         LDA $EB         ; ...
         BPL C3CD02      ; ...
         LDA $E0         ; ...
         EOR #$FFFF      ; ...
         INC A           ; ...
         BRA C3CD04      ; ...
C3CD02:  LDA $E0         ; ...
C3CD04:  LDX $2D         ; Queue index
         CLC             ; Prepare ADC
         ADC $3549,X     ; Add base Y
         STA $3449,X     ; Set bird's Y
         INC $3349,X     ; Pos index +1
         SEP #$20        ; ...
         JSR C31221      ; Define OAM
         SEC             ; Set to requeue
         RTS

; 14: Start frontview airship scene
C3CD17:  JSL $D4CED7     ; Init registers
         JSR C3C59F      ; Color math: BG1
         JSL C3D573      ; Upload GFX, map
         JSR C3CA71      ; Get sky; init M7
         JSR C3D38C      ; Queue gradient
         JSR C3D36F      ; HDMA: Color math
         JSR C3C751      ; Load OBJ colors
         LDY #$0028      ; Y: 40
         STY $3B         ; Set BG2 Y-Pos
         LDY #$FFCD      ; Mod index: 205
         STY $C3         ; Set matrices'
         LDY #$030B      ; Vertical angle
         STY $C7         ; Set for field
         LDY #$F000      ; Base divisor
         STY $C5         ; Set matrices'
         JSR C3DDD2      ; Make matrix tbl
         JSR C3D173      ; Load BG1 colors
         JSR C3CB2E      ; Create birds
         JSR C3CFDC      ; Queue airship
         REP #$20        ; 16-bit A
         LDA #$8C25      ; Anim table ptr
         STA $7E32C9,X   ; Set airship's
         SEP #$20        ; 8-bit A
         LDA #$C2        ; Bank: C2
         STA $7E35CA,X   ; Set ptr HB
         LDA #$78        ; X: 120
         STA $7E33CA,X   ; Set airship's
         LDA #$58        ; Base Y: 88
         STA $7E354A,X   ; Set airship's
         LDY #$8B39      ; Anim ptr LBs
         LDA #$C2        ; Anim ptr HB
         JSR C3D225      ; Queue field anim
         JSR C3D9C5      ; Build text OAM
         LDY $00         ; Scene timer: 0
         STY $CF         ; Set for text
         LDA #$02        ; Min slot: 16
         LDY #C3D897     ; C3/D897
         JSR C31173      ; Queue credits
         LDA #$03        ; Min slot: 24
         LDY #C3CAB0     ; C3/CAB0
         JSR C31173      ; Set to pan sky
         JSR C3D2A0      ; Queue M7 handler
         INC $26         ; Next: Late flock
         LDY #$04B0      ; Frames: 1200
         STY $20         ; Set flock delay
         JMP C3C66C      ; Queue fade-in

; Queue bird from late flock
C3CD97:  LDA #$02        ; Min slot: 16
         LDY #C3CDEA     ; C3/CDEA
         JSR C31173      ; Queue anim fn
         RTS

; 15: Show late bird flock
C3CDA0:  LDY $20         ; Delay expired?
         BNE C3CDE9      ; Exit if not
         LDA #$03        ; C3/C8A6
         STA $26         ; Next: Fade-out
         LDY #$0708      ; Frames: 1800
         STY $20         ; Set fade delay
         JSR C3CD97      ; Queue bird 1
         LDA #$00        ; X: 0
         STA $7E33CA,X   ; Set for bird 1
         LDA #$50        ; Y: 80
         STA $7E344A,X   ; Set for bird 1
         JSR C3CD97      ; Queue bird 2
         LDA #$18        ; X: 24
         STA $7E33CA,X   ; Set for bird 2
         LDA #$40        ; Y: 64
         STA $7E344A,X   ; Set for bird 2
         JSR C3CD97      ; Queue bird 3
         LDA #$40        ; X: 64
         STA $7E33CA,X   ; Set for bird 3
         LDA #$68        ; Y: 104
         STA $7E344A,X   ; Set for bird 3
         JSR C3CD97      ; Queue bird 4
         LDA #$10        ; X: 16
         STA $7E33CA,X   ; Set for bird 4
         LDA #$48        ; Y: 72
         STA $7E344A,X   ; Set for bird 4
C3CDE9:  RTS

; Animate bird from late flock
C3CDEA:  TAX             ; Index mode
         JMP (C3CDEE,X)  ; Handle mode

; Jump table for the above
C3CDEE:  dw C3CE00       ; Initialize data
         dw C3CE1F       ; Unused
         dw C3CE1F       ; Head E after delay
         dw C3CE1F       ; Head SE after delay
         dw C3CE1F       ; Head SSE after delay
         dw C3CE1F       ; Head SSW after delay
         dw C3CE1F       ; Head SW after delay
         dw C3CE1F       ; Head SW x2 after delay
         dw C3CE33       ; Delete if at left edge

; Mode 0: Initialize data
C3CE00:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         REP #$20        ; 16-bit A
         LDA #$F74F      ; Anim table ptr
         STA $32C9,X     ; Set bird's
         SEP #$20        ; 8-bit A
         LDA #$CF        ; Bank: CF
         STA $35CA,X     ; Set ptr HB
         STZ $35C9,X     ; Course: NE
         JSR C3CE43      ; Define path
         LDX $2D         ; Queue index
         JSR C31206      ; Set pose timer

; Modes 1-7: Alter course
C3CE1F:  LDX $2D         ; Queue index
         LDY $3349,X     ; Mode expired?
         BNE C3CE2B      ; Branch if not
         JSR C3CE43      ; Alter path
         LDX $2D         ; Queue index
C3CE2B:  JSR C3CFE5      ; Mode timer -1
         JSR C3DEC0      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS

; Mode 8: Delete if set to wrap horizontally
C3CE33:  JSR C3DEC0      ; Scroll & OAM
         LDX $2D         ; Queue index
         LDA $33CA,X     ; Bird's X
         CMP #$01        ; Zero?
         BCS C3CE41      ; Maintain if not
         CLC             ; Set to dequeue
         RTS             ; Exit
C3CE41:  SEC             ; Set to requeue
         RTS

; Alter course of bird from late flock
C3CE43:  LDY $2D         ; Queue index
         TYX             ; Put it in X
         TDC             ; Clear A
         LDA $35C9,Y     ; Path index
         INC $35C9,X     ; Path Index +1
         INC $3649,X     ; Mode +1
         ASL A           ; Index x2
         ASL A           ; Index x4
         ASL A           ; Index x8
         REP #$20        ; 16-bit A
         TAX             ; Index it
         LDA.L C3CE6E,X  ; H-Speed
         STA $34C9,Y     ; Set bird's
         LDA.L C3CE70,X  ; V-Speed
         STA $3549,Y     ; Set bird's
         LDA.L C3CE72,X  ; Path timer
         STA $3349,Y     ; Set bird's
         SEP #$20        ; 8-bit A
         RTS

; Late bird flock's course
C3CE6E:  dw $0020        ; H-Speed: +0.125 px
C3CE70:  dw $FFF0        ; V-Speed: -0.0625 px
C3CE72:  dw $0384        ; Frames: 900
         dw $0000        ; ...
         dw $0020        ; H-Speed: +0.125 px
         dw $0000        ; V-Speed: 0
         dw $003C        ; Frames: 60
         dw $0000        ; ...
         dw $0020        ; H-Speed: +0.125 px
         dw $0020        ; V-Speed: +0.125 px
         dw $003C        ; Frames: 60
         dw $0000        ; ...
         dw $0010        ; H-Speed: +0.0625 px
         dw $0040        ; V-Speed: +0.25 px
         dw $003C        ; Frames: 60
         dw $0000        ; ...
         dw $FFE0        ; H-Speed: -0.125 px
         dw $0040        ; V-Speed: +0.25 px
         dw $003C        ; Frames: 60
         dw $0000        ; ...
         dw $FFC0        ; H-Speed: -0.25 px
         dw $0040        ; V-Speed: +0.25 px
         dw $00B4        ; Frames: 180
         dw $0000        ; ...
         dw $FF80        ; H-Speed: -0.5 px
         dw $0080        ; V-Speed: +0.5 px
         dw $00B4        ; Frames: 180
         dw $0000        ; ...

; 18: Start aerial-view plains scene
C3CEA6:  JSL $D4CED7     ; Init registers
         JSR C3C59F      ; Color math: BG1
         JSL C3D573      ; Upload GFX, map
         JSR C3D3E6      ; Reset M7 vars
         JSL $D4CB8F     ; HDMA: Matrices
         LDY #$1800      ; Base divisor
         STY $C5         ; Set matrices'
         JSR C3DDD2      ; Make matrix tbl
         JSR C3D15C      ; Make text black
         JSR C3D173      ; Load BG1 colors
         LDY #$8AFA      ; Anim ptr LBs
         LDA #$C2        ; Anim ptr HB
         JSR C3D225      ; Queue field anim
         JSR C3D9DB      ; Build text OAM
         LDY $00         ; Scene timer: 0
         STY $CF         ; Set for text
         LDA #$02        ; Min slot: 16
         LDY #C3D8E5     ; C3/D8E5
         JSR C31173      ; Queue credits
         JSR C3D2A0      ; Queue M7 handler
         LDA #$03        ; C3/C8A6
         STA $26         ; Next: Fade-out
         LDY #$0E10      ; Frames: 3600
         STY $20         ; Set fade delay
         JMP C3C66C      ; Queue fade-in

; 1C: Start rearview airship scene
C3CEEC:  JSL $D4CED7     ; Init registers
         JSL C3D573      ; Upload GFX, map
         JSR C3D144      ; Upload balloon
         JSR C3CA71      ; Get sky; init M7
         JSR C3D38C      ; Queue gradient
         JSR C3D36F      ; HDMA: Color math
         LDY #$0100      ; Base divisor
         STY $C5         ; Set matrices'
         LDY #$02DC      ; Vertical angle
         STY $C7         ; Set for field
         JSR C3DDD2      ; Make matrix tbl
         LDY #$0010      ; Y: 16
         STY $3B         ; Set BG2 Y-Pos
         JSR C3D15C      ; Make text black
         JSR C3C751      ; Load OBJ colors
         JSR C3D173      ; Load BG1 colors
         JSR C3D9E6      ; Build text OAM
         LDY $00         ; Scene timer: 0
         STY $CF         ; Set for text
         LDA #$02        ; Min slot: 16
         LDY #C3D933     ; C3/D933
         JSR C31173      ; Queue credits
         LDA #$00        ; Min slot: 0
         LDY #C3CF9A     ; C3/CF9A
         JSR C31173      ; Queue BG scroll
         JSR C3CFB2      ; Queue SW rotor
         LDA #$14        ; Y: 20
         STA $7E354A,X   ; Set SW rotor's
         LDA #$44        ; X: 68
         STA $7E33CA,X   ; Set SW rotor's
         JSR C3CFC7      ; Queue SE rotor
         LDA #$14        ; Y: 20
         STA $7E354A,X   ; Set SE rotor's
         LDA #$AC        ; X: 172
         STA $7E33CA,X   ; Set SE rotor's
         JSR C3CFB2      ; Queue NW rotor
         LDA #$E8        ; Y: 232
         STA $7E354A,X   ; Set NW rotor's
         LDA #$60        ; X: 96
         STA $7E33CA,X   ; Set NW rotor's
         JSR C3CFC7      ; Queue NE rotor
         LDA #$E8        ; Y: 232
         STA $7E354A,X   ; Set NE rotor's
         LDA #$90        ; X: 144
         STA $7E33CA,X   ; Set NE rotor's
         JSR C3CFDC      ; Queue airship
         REP #$20        ; 16-bit A
         LDA #$8C60      ; Anim table ptr
         STA $7E32C9,X   ; Set airship's
         SEP #$20        ; 8-bit A
         LDA #$C2        ; Bank: C2
         STA $7E35CA,X   ; Set ptr HB
         LDA #$48        ; X: 72
         STA $7E33CA,X   ; Set airship's
         LDA #$F8        ; Y: 248
         STA $7E354A,X   ; Set airship's
         LDA #$03        ; C3/C8A6
         STA $26         ; Next: Fade-out
         LDY #$08AC      ; Frames: 2220
         STY $20         ; Set fade delay
         JMP C3C66C      ; Queue fade-in

; Scroll field and sky for rearview airship scene
C3CF9A:  LDA $23         ; NMI count
         AND #$7F        ; 0 or 128?
         BNE C3CFA2      ; Branch if not
         INC $3B         ; Shift sky up
C3CFA2:  LDA $23         ; NMI count
         AND #$01        ; Odd value?
         BNE C3CFB0      ; Exit if so
         REP #$20        ; 16-bit A
         DEC $B9         ; Center Y -1
         DEC $37         ; Move field down
         SEP #$20        ; 8-bit A
C3CFB0:  SEC             ; Set to requeue
         RTS

; Queue NW or SW airship rotor
C3CFB2:  JSR C3CFDC      ; Queue anim fn
         LDA #$C2        ; Bank: C2
         STA $7E35CA,X   ; Set ptr HB
         REP #$20        ; 16-bit A
         LDA #$8D3E      ; Anim ptr LBs
         STA $7E32C9,X   ; Set sprite's
         SEP #$20        ; 8-bit A
         RTS

; Queue NE or SE airship rotor
C3CFC7:  JSR C3CFDC      ; Queue anim fn
         LDA #$C2        ; Bank: C2
         STA $7E35CA,X   ; Set ptr HB
         REP #$20        ; 16-bit A
         LDA #$8D91      ; Anim ptr LBs
         STA $7E32C9,X   ; Set sprite's
         SEP #$20        ; 8-bit A
         RTS

; Queue frontview or rearview airship or rotor
C3CFDC:  LDA #$02        ; Min slot: 16
         LDY #C3CFF8     ; C3/CFF8
         JSR C31173      ; Queue OAM fn
         RTS

; Decrease sprite's animation mode timer
C3CFE5:  LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         DEC $3349,X     ; Timer -1
         SEP #$20        ; 8-bit A
         RTS

; Define sprite's animation mode timer (unused)
C3CFEF:  REP #$20        ; 16-bit A
         TYA             ; Get timer
         STA $3349,X     ; Set timer
         SEP #$20        ; 8-bit A
         RTS

; Animate frontview or rearview airship or rotor
C3CFF8:  TAX             ; Index mode
         JMP (C3CFFC,X)  ; Handle mode

; Jump table
C3CFFC:  dw C3D000       ; Initialize timers
         dw C3D00B       ; Sustain sprite

; Mode 0: Initialize timers
C3D000:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         STZ $3349,X     ; Anim timer: 0
         JSR C31206      ; Set pose timer

; Mode 1: Sustain sprite
C3D00B:  LDX $2D         ; Queue index
         JSR C3CBFF      ; Set altitute
         INC $3349,X     ; Anim timer +1
         JSR C31221      ; Define OAM
         SEC             ; Set to requeue
         RTS

; Load colors for blue sky and non-sprite airships
C3D018:  LDA #$C2        ; Source HB
         LDY #$3049      ; To BG pal 0
         LDX #$959C      ; Source LBs
         JSR C30F8E      ; Load fill color
         LDA #$C2        ; Source HB
         LDY #$3069      ; To BG pal 1
         LDX #$959C      ; Source LBs
         JSR C30F8E      ; Load the rest
         RTS

; 20: Start final airship scene
C3D02F:  JSL $D4CED7     ; Init registers
         JSR C3C59F      ; Color math: BG1
         LDA #$80        ; Map wraps: No
         STA $211A       ; Set M7 settings
         JSR C3D60A      ; Upload GFX, map
         JSR C3D3E6      ; Reset M7 vars
         JSL $D4CE55     ; HDMA: MS desig
         LDA #$C2        ; Source HB
         LDY #$31C9      ; To OBJ pal 4
         LDX #$9754      ; Source LBs
         JSR C30F8E      ; No text...
         LDA #$C2        ; Source HB
         LDY #$31E9      ; To OBJ pal 5
         LDX #$974C      ; Source LBs
         JSR C30F8E      ; No text...
         JSR C3D173      ; No field...
         JSR C3D018      ; Load BG colors
         LDY #$0001      ; Zoom-out: 1
         STY $BB         ; Set matrix A
         STY $C1         ; Set matrix D
         LDY #$0008      ; X: 8
         STY $B7         ; Set center X
         LDY #$0018      ; Y: 24
         STY $B9         ; Set center Y
         LDY #$FFD8      ; X: -40
         STY $35         ; Set BG1 X-Pos
         LDY #$FFD0      ; Y: -48
         STY $37         ; Set BG1 Y-Pos
         LDA #$00        ; Min slot: 0
         LDY #C3D122     ; C3/D122
         JSR C31173      ; Queue zoom-out
         INC $26         ; Next: C3/D096
         LDY #$0096      ; Frames: 150
         STY $20         ; Set fade delay
         LDA #$00        ; Min slot: 0
         LDY #C3D0A8     ; C3/D0A8
         JSR C31173      ; Queue rotor fn
         JMP C3C66C      ; Queue fade-in

; 21: Fade final airship
C3D096:  LDY $20         ; Delay expired?
         BNE C3D0A7      ; Exit if not
         STZ $26         ; Next: Fade-out
         LDY #$0078      ; Frames: 120
         STY $20         ; Set fade timer
         JSR C3E16B      ; Fade BG pal 1+2
         JSR C3E241      ; Fade BG pal 0
C3D0A7:  RTS

; Animate final airship's rotors
C3D0A8:  LDA $23         ; NMI count
         AND #$01        ; Even value?
         BEQ C3D0BF      ; Branch if so
         LDA #$51        ; Tile: 81
         STA $7E9849     ; Set L-Rotor's
         LDA #$4F        ; Tile: 79
         STA $7E984A     ; Set R-Rotor's
         JSR C3D0D0      ; Queue upload
         SEC             ; Set to requeue
         RTS             ; Exit
C3D0BF:  LDA #$59        ; Tile: 89
         STA $7E9849     ; Set L-Rotor's
         LDA #$5A        ; Tile: 90
         STA $7E984A     ; Set R-Rotor's
         JSR C3D0D0      ; Queue upload
         SEC             ; Set to requeue
         RTS

; Set to refresh final airship's rotors
C3D0D0:  LDY #$0283      ; L-Rotor adr
         STY $14         ; Set VRAM ptr1
         LDY #$9849      ; 7E/9849
         STY $16         ; Set src1 LBs
         LDY #$0206      ; R-Rotor adr
         STY $1B         ; Set VRAM ptr2
         LDY #$984A      ; 7E/984A
         STY $1D         ; Set src2 LBs
         LDA #$7E        ; Bank: 7E
         STA $18         ; Set src1 HB
         STA $1F         ; Set src2 HB
         LDY #$0001      ; Bytes: 1
         STY $12         ; Set src1 size
         STY $19         ; Set src2 size
         RTS

; Animate sideview airship's rotors
C3D0F2:  LDA $23         ; NMI count
         AND #$01        ; Even value?
         BEQ C3D103      ; Branch if so
         LDA #$58        ; Tile: 88
         STA $7E9849     ; Set rotors'
         JSR C3D10E      ; Queue upload
         SEC             ; Set to requeue
         RTS             ; Exit
C3D103:  LDA #$34        ; Tile: 52
         STA $7E9849     ; Set rotors'
         JSR C3D10E      ; Queue upload
         SEC             ; Set to requeue
         RTS

; Set to refresh sideview airship's rotors
C3D10E:  LDY #$0892      ; $1124
         STY $14         ; Set VRAM ptr
         LDY #$9849      ; 7E/9849
         STY $16         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $18         ; Set src HB
         LDY #$0001      ; Bytes: 1
         STY $12         ; Set data size
         RTS

; Process queued zoom-out for final airship scene
C3D122:  JSR C3D127      ; Zoom out
         SEC             ; Set to requeue
         RTS

; Zoom out from final airship
C3D127:  LDA $23         ; NMI count
         AND #$07        ; Now 0-7
         BNE C3D137      ; Branch if > 0
         LDY $B9         ; M7 center Y
         DEY             ; Subtract 1
         STY $B9         ; Save changes
         LDY $B7         ; M7 center X
         INY             ; Add 1
         STY $B7         ; Save changes
C3D137:  REP #$20        ; 16-bit A
         INC $BB         ; Matrix A +1
         INC $BB         ; Matrix A +1
         INC $C1         ; Matrix D +1
         INC $C1         ; Matrix D +1
         SEP #$20        ; 8-bit A
         RTS

; Upload rearview airship's balloon graphics
C3D144:  LDY #$D7BA      ; 7E/D7BA
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         LDY #$0580      ; Bytes: 1408
         STY $EB         ; Set data size
         STZ $ED         ; Attrib LB: 0
         STZ $EE         ; Attrib HB: 0
         LDY #$6C00      ; VRAM pointer
         JMP C3DDB9      ; Upload data

; Initialize credits' colors to black for fade-in
C3D15C:  LDA #$C3        ; Src HB
         LDY #$31C9      ; To OBJ pal 4
         LDX #C310F4     ; Src LBs
         JSR C30F8E      ; Do big font
         LDA #$C3        ; Src HB
         LDY #$31E9      ; To OBJ pal 5
         LDX #C310F4     ; Src LBs
         JSR C30F8E      ; Do small font
         RTS

; Load BG1 palettes for credits scenes
C3D173:  LDA #$C2        ; Src HB
         LDY #$3069      ; To BG pal 1
         LDX #$95BC      ; Src LBs
         JSR C30F8E      ; C3/D02B...
         LDA #$C2        ; Src HB
         LDY #$3089      ; To BG pal 2
         LDX #$95DC      ; Src LBs
         JSR C30F8E      ; Do sea
         LDA #$C2        ; Src HB
         LDY #$30A9      ; To BG pal 3
         LDX #$95FC      ; Src LBs
         JSR C30F8E      ; Do clouds
         LDA #$C2        ; Src HB
         LDY #$30C9      ; To BG pal 4
         LDX #$961C      ; Src LBs
         JSR C30F8E      ; Do trees
         LDA #$C2        ; Src HB
         LDY #$3109      ; To BG pal 6
         LDX #$963C      ; Src LBs
         JSR C30F8E      ; Do lake
         LDA #$C2        ; Src HB
         LDY #$3129      ; To BG pal 7
         LDX #$965C      ; Src LBs
         JSR C30F8E      ; Do grass
         RTS

; Scroll actor's pseudonym down
C3D1B6:  LDY $CF         ; Scroll timer
         CPY $64         ; At endpoint?
         BEQ C3D1CA      ; Dequeue if so
         LDA $23         ; NMI count
         AND #$03        ; Now 0-3
         BNE C3D1C8      ; Exit if 1-3
         REP #$20        ; 16-bit A
         DEC $3F         ; BG3 camera up
         SEP #$20        ; 8-bit A
C3D1C8:  SEC             ; Set to requeue
         RTS             ; Exit
C3D1CA:  CLC             ; Set to dequeue
         RTS

; Process queued field fade-in
C3D1CC:  TAX             ; Index mode
         JMP (C3D1D0,X)  ; Handle mode

; Jump table
C3D1D0:  dw C3D1D4       ; Initialize brightness
         dw C3D1E3       ; Increase brightness

; Mode 0: Initialize brightness
C3D1D4:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         LDA #$01        ; BRT: 1 and ON
         STA $344A,X     ; Set next BRT
         LDA #$0F        ; Frames: 15
         STA $3349,X     ; Set timer

; Mode 1: Increase brightness
C3D1E3:  LDX $2D         ; Queue index
         LDA $3349,X     ; Timer expired?
         BEQ C3D1F7      ; Finalize if so
         LDA $344A,X     ; Next brightness
         STA $44         ; Set as current
         INC $344A,X     ; Next BRT +1
         DEC $3349,X     ; Timer -1
         SEC             ; Set to requeue
         RTS             ; Exit
C3D1F7:  LDA #$0F        ; BRT: 15 and ON
         STA $44         ; Set brightness
         CLC             ; Set to dequeue
         RTS

; Process queued field fade-out
C3D1FD:  TAX             ; Index mode
         JMP (C3D201,X)  ; Handle mode

; Jump table
C3D201:  dw C3D205       ; Initialize brightness
         dw C3D20F       ; Decrease brightness

; Mode 0: Initialize brightness
C3D205:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         LDA #$0F        ; BRT: 15 and ON
         STA $33CA,X     ; Set next BRT

; Mode 1: Decrease brightness
C3D20F:  LDY $20         ; Timer expired?
         BEQ C3D21F      ; Finalize if so
         LDX $2D         ; Queue index
         LDA $33CA,X     ; Next brightness
         STA $44         ; Set as current
         DEC $33CA,X     ; Next BRT -1
         SEC             ; Set to requeue
         RTS             ; Exit
C3D21F:  LDA #$80        ; BRT: 0 and OFF
         STA $44         ; Set brightness
         CLC             ; Set to dequeue
         RTS

; Queue Mode 7 animation script loading
C3D225:  PHA             ; Save ptr HB
         PHY             ; Save ptr LBs
         LDA #$01        ; Min slot: 8
         LDY #C3D23F     ; C3/D23F
         JSR C31173      ; Queue anim fn
         REP #$20        ; 16-bit A
         PLY             ; Anim ptr LBs
         TYA             ; Put in A
         STA $7E32C9,X   ; Put in queue
         SEP #$20        ; 8-bit A
         PLA             ; Anim ptr HB
         STA $7E35CA,X   ; Put in queue
         RTS

; Load parameters for Mode 7 animation
C3D23F:  TAX             ; Index mode
         JMP (C3D243,X)  ; Handle mode

; Jump table for the above
C3D243:  dw C3D247       ; Initialize timer
         dw C3D24F       ; Load animation flags

; Mode 0: Initialize sequence timer
C3D247:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         JSR C31206      ; Set anim timer

; Mode 1: Load animation flags
C3D24F:  LDX $2D         ; Queue index
         JSR C31227      ; Anim timer -1
         TDC             ; Clear A
         LDA $36C9,X     ; Anim index
         TAY             ; Index it
         REP #$20        ; 16-bit A
         LDA [$EB],Y     ; Anim flags
         STA $04         ; Set as current
         SEP #$20        ; 8-bit A
         SEC             ; Set to requeue
         RTS

; Refresh Mode 7 registers (NMI)
C3D263:  LDA $BB         ; Matrix A LB
         STA $211B       ; To register
         LDA $BC         ; Matrix A HB
         STA $211B       ; To register
         LDA $BD         ; Matrix B LB
         STA $211C       ; To register
         LDA $BE         ; Matrix B HB
         STA $211C       ; To register
         LDA $BF         ; Matrix C LB
         STA $211D       ; To register
         LDA $C0         ; Matrix C HB
         STA $211D       ; To register
         LDA $C1         ; Matrix D LB
         STA $211E       ; To register
         LDA $C2         ; Matrix D HB
         STA $211E       ; To register
         LDA $B7         ; Center X LB
         STA $211F       ; To register
         LDA $B8         ; Center X HB
         STA $211F       ; To register
         LDA $B9         ; Center Y LB
         STA $2120       ; To register
         LDA $BA         ; Center Y HB
         STA $2120       ; To register
         RTS

; Queue Mode 7 animation script decoding
C3D2A0:  LDA #$00        ; Min slot: 0
         LDY #C3D2A9     ; C3/D2A9
         JSR C31173      ; Queue anim fn
         RTS

; Decode parameters for Mode 7 animation
C3D2A9:  LDA $04         ; Anim flags
         BIT #$10        ; Tilt right?
         BEQ C3D2B7      ; Skip if not
         REP #$20        ; 16-bit A
         INC $C3         ; Mod index +1
         SEP #$20        ; 8-bit A
         INC $59         ; No use...

; Fork: Rotate counterclockwise
C3D2B7:  LDA $04         ; Anim flags
         BIT #$20        ; Tilt left?
         BEQ C3D2C5      ; Skip if not
         REP #$20        ; 16-bit A
         DEC $C3         ; Mod index -1
         SEP #$20        ; 8-bit A
         DEC $59         ; No use...

; Fork: Rotate forward
C3D2C5:  LDA $04         ; Anim flags
         BIT #$40        ; Tilt up?
         BEQ C3D2D1      ; Skip if not
         REP #$20        ; 16-bit A
         INC $C7         ; Matrix mod +1
         SEP #$20        ; 8-bit A

; Fork: Rotate backward
C3D2D1:  LDA $05         ; Anim flags
         BIT #$40        ; Tilt down?
         BEQ C3D2DD      ; Skip if not
         REP #$20        ; 16-bit A
         DEC $C7         ; Matrix mod -1
         SEP #$20        ; 8-bit A

; Fork: Zoom in
C3D2DD:  LDA $04         ; Anim flags
         BIT #$80        ; Inc divisor?
         BEQ C3D2E5      ; Skip if not
         INC $C6         ; Divisor +1

; Fork: Zoom out
C3D2E5:  LDA $05         ; Anim flags
         BIT #$80        ; Dec divisor?
         BEQ C3D2ED      ; Skip if not
         DEC $C6         ; Divisor -1

; Fork: Scroll southward
C3D2ED:  LDA $05         ; Anim flags
         BIT #$08        ; Scroll down?
         BEQ C3D2FB      ; Skip if not
         REP #$20        ; 16-bit A
         DEC $B9         ; Center Y -1
         DEC $37         ; BG1 Y-Pos -1
         SEP #$20        ; 8-bit A

; Fork: Scroll northward
C3D2FB:  LDA $05         ; Anim flags
         BIT #$04        ; Scroll up?
         BEQ C3D309      ; Skip if not
         REP #$20        ; 16-bit A
         INC $B9         ; Center Y +1
         INC $37         ; BG1 Y-Pos +1
         SEP #$20        ; 8-bit A

; Fork: Scroll eastward
C3D309:  LDA $05         ; Anim flags
         BIT #$02        ; Scroll right?
         BEQ C3D317      ; Skip if not
         REP #$20        ; 16-bit A
         DEC $B7         ; Center X -1
         DEC $35         ; BG1 X-Pos -1
         SEP #$20        ; 8-bit A

; Fork: Scroll westward
C3D317:  LDA $05         ; Anim flags
         BIT #$01        ; Scroll left?
         BEQ C3D325      ; Skip if not
         REP #$20        ; 16-bit A
         INC $B7         ; Center X +1
         INC $35         ; BG1 X-Pos +1
         SEP #$20        ; 8-bit A

; Fork: Build Mode 7 matrix tables
C3D325:  JSR C3D338      ; Cap center X/Y
         REP #$20        ; 16-bit A
         LDA $04         ; Anim flags
         AND #$F0FF      ; Only scrolling?
         SEP #$20        ; 8-bit A
         BEQ C3D336      ; Exit if so
         JSR C3DDD2      ; Build tables
C3D336:  SEC             ; Set to requeue
         RTS

; Keep Mode 7 center X and Y within boundaries
C3D338:  REP #$20        ; 16-bit A
         LDA $B7         ; Center X
         AND #$1FFF      ; Clear excess
         STA $B7         ; Save changes
         LDA $B9         ; Center Y
         AND #$1FFF      ; Clear excess
         STA $B9         ; Save changes
         SEP #$20        ; 8-bit A
         RTS

; Configure Mode 7 not to apply to cloudy sky
C3D34B:  JSL $D4CB8F     ; HDMA: Matrices
         STZ $4310       ; 1Rx1B to PPU
         LDA #$05        ; $2105
         STA $4311       ; To BG mode
         LDY #C3D36A     ; C3/D36A
         STY $4312       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4314       ; Set src HB
         STA $4317       ; Set indir HB
         LDA #$02        ; Channel: 1
         TSB $43         ; Queue HDMA-1
         RTS

; BG mode and tile size per scanline
C3D36A:  db $47,$01      ; Mode 1, 8x8 tiles
         db $01,$07      ; Mode 7
         db $00          ; End

; Set color addition and math for field and for cloudy sky
C3D36F:  LDA #$01        ; 2Rx1B to PPU
         STA $4330       ; Set DMA mode
         LDA #$30        ; $2130, $2131
         STA $4331       ; To color regs
         LDY #C3D3A7     ; C3/D3A7
         STY $4332       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4334       ; Set src HB
         STA $4337       ; Set indir HB
         LDA #$08        ; Channel: 3
         TSB $43         ; Queue HDMA-3
         RTS

; Queue gradient effect for field under sky
C3D38C:  STZ $4320       ; 1Rx1B to PPU
         LDA #$32        ; $2132
         STA $4321       ; To fixed color
         LDY #C3D3AE     ; C3/D3AE
         STY $4322       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4324       ; Set src HB
         STA $4327       ; Set indir HB
         LDA #$04        ; Channel: 2
         TSB $43         ; Queue HDMA-2
         RTS

; Color addition and math per scanline
C3D3A7:  db $47,$80,$41  ; BG1, inside window, half mode
C3D3AA:  db $01,$82,$01  ; BG1, inside window, add subscreen
C3D3AD:  db $00          ; End

; Gradient table for the above
C3D3AE:  db $47,$E0      ; RGB: 0
C3D3B0:  db $01,$ED      ; RGB: 13
C3D3B2:  db $01,$EB      ; RGB: 11
C3D3B4:  db $01,$EA      ; RGB: 10
C3D3B6:  db $02,$E9      ; RGB: 9
C3D3B8:  db $03,$E8      ; RGB: 8
C3D3BA:  db $04,$E7      ; RGB: 7
C3D3BC:  db $05,$E6      ; RGB: 6
C3D3BE:  db $06,$E5      ; RGB: 5
C3D3C0:  db $07,$E4      ; RGB: 4
C3D3C2:  db $08,$E3      ; RGB: 3
C3D3C4:  db $0C,$E2      ; RGB: 2
C3D3C6:  db $0F,$E1      ; RGB: 1
C3D3C8:  db $1E,$E0      ; RGB: 0
C3D3CA:  db $00          ; End

; Queue adjustable gradient effect (unused)
C3D3CB:  STZ $4320       ; 1Rx1B to PPU
         LDA #$32        ; $2132
         STA $4321       ; To fixed color
         LDY #$9849      ; 7E/9849
         STY $4322       ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $4324       ; Set src HB
         STA $4327       ; Set indir HB
         LDA #$04        ; Channel: 2
         TSB $43         ; Queue HDMA-2
         RTS

; Reset Mode 7 parameters
C3D3E6:  LDY #$0100      ; 256
         STY $B7         ; Set center X
         LDY #$0080      ; 128
         STY $B9         ; Set center Y
         STY $35         ; Set BG1 X-Pos
         TDC             ; Clear A
         TAY             ; Clear Y
         STY $37         ; BG1 Y-Pos: 0
         STZ $58         ; No use...
         LDA #$40        ; No use...
         STA $59         ; No use...
         LDY #$0000      ; Vertical angle
         STY $C7         ; Set for BG1
         LDY #$0100      ; Base divisor
         STY $C5         ; Set matrices'
         LDY #$0000      ; Mod index: 0
         STY $C3         ; Set matrices'
         RTS

; Unpack and upload graphics and tilemaps for sideview airship scene
C3D40C:  JSR C3D439      ; Upload font GFX
         JSR C3D6B1      ; Unpack map, GFX
         JSR C3D66B      ; Pal numbers loc
         JSR C3D552      ; Convert M7 GFX A
         JSR C3D42A      ; Insert tilemap A
         JSR C3D634      ; Upload M7 map A
         JSR C3D66B      ; Pal numbers loc
         JSR C3D562      ; Convert M7 GFX B
         JSR C3D42A      ; Insert tilemap B
         JMP C3D64C      ; Upload M7 map B

; Assemble half of tilemap for sideview airship scene
C3D42A:  JSR C3D68D      ; Set ptrs loc
         LDX #$FC1A      ; Tiles loc
         STX $F1         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $F3         ; Set src HB
         JMP C3D706      ; Build map

; Unpack and upload font graphics for credits
C3D439:  LDY #$BA00      ; Source LBs
         LDA #$C4        ; Source HB
         JSR C3DD61      ; Load big font
         JSR C3D497      ; Set as 16x16
         LDY #$C000      ; 7E/C000
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         LDY #$0C00      ; Bytes: 3072
         STY $EB         ; Set data size
         LDY #$7000      ; VRAM pointer
         JSR C3DD86      ; Upload font
         LDY #$87C0      ; C4/87C0
         STY $E7         ; Set src LBs
         LDA #$C4        ; Bank: C4
         STA $E9         ; Set src HB
         LDY #$0200      ; Bytes: 512
         STY $EB         ; Set data size
         LDY #$7E00      ; VRAM pointer
         JSR C3DD86      ; Do small font
         JMP C3D46F      ; ...

; Upload period and space character for special thanks
C3D46F:  LDY #$8C10      ; C4/8C10
         STY $E7         ; Set src LBs
         LDA #$C4        ; Bank: C4
         STA $E9         ; Set src HB
         LDY #$0010      ; Bytes: 16
         STY $EB         ; Set data size
         LDY #$7FA0      ; VRAM pointer
         JSR C3DD86      ; Upload period
         LDY #$8FB0      ; C4/8FB0
         STY $E7         ; Set src LBs
         LDA #$C4        ; Bank: C4
         STA $E9         ; Set src HB
         LDY #$0010      ; Bytes: 16
         STY $EB         ; Set data size
         LDY #$7FB0      ; VRAM pointer
         JMP C3DD86      ; Upload space

; Expand large font graphics to 16x16 for credits
C3D497:  PHB             ; Save DB
         LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         LDX $00         ; ROM index: 0
         TXY             ; Dst index: 0
C3D49F:  PHX             ; Save ROM index
         TDC             ; Clear A
         LDA $C29854,X   ; Tile index
         REP #$20        ; 16-bit A
         ASL A           ; x2
         ASL A           ; x4
         ASL A           ; x8
         ASL A           ; x16
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDA #$10        ; Rows: 8
         STA $E0         ; Set counter
C3D4B2:  LDA $C000,X     ; 8 px, 1 plane
         STA $C400,Y     ; Put in buffer
         INX             ; Src index +1
         INY             ; Dst index +1
         DEC $E0         ; Counter -1
         BNE C3D4B2      ; Loop till zero

; Fork: Blank right-hand 8x8 tile
C3D4BE:  TDC             ; Clear A
         TAX             ; Counter: 0
C3D4C0:  STA $C400,Y     ; Clear a plane
         INY             ; Dst index +1
         INX             ; Counter +1
         CPX #$0010      ; Done 8 rows?
         BNE C3D4C0      ; Loop if not
         PLX             ; ROM index
         INX             ; ROM index +1
         CPX #$0040      ; Done 64 tiles?
         BNE C3D49F      ; Loop if not
         PLB             ; Restore DB
         RTS

; Unpack and upload cloudy sky graphics and tilemap
C3D4D3:  REP #$20        ; 16-bit A
         LDA $EEB206     ; Source LBs
         TAY             ; Put in Y
         SEP #$20        ; 8-bit A
         LDA $EEB208     ; Source HB
         JSR C3DD61      ; Unpack graphics
         JSR C3D518      ; Src: 7E/C000
         LDY #$1A20      ; Bytes: 6688
         STY $EB         ; Set data size
         STZ $ED         ; Attrib LB: 0
         STZ $EE         ; Attrib HB: 0
         LDY #$4000      ; VRAM pointer
         JSR C3DDB9      ; Upload graphics
         REP #$20        ; 16-bit A
         LDA $EEB209     ; Source LBs
         TAY             ; Put in Y
         SEP #$20        ; 8-bit A
         LDA $EEB20B     ; Source HB
         JSR C3DD61      ; Unpack tilemap
         LDY #$2000      ; Add: Priority
         STY $ED         ; Set complement
         JSR C3D518      ; Src: 7E/C000
         LDY #$0400      ; Bytes: 1024
         STY $EB         ; Set data size
         LDY #$5000      ; VRAM pointer
         JMP C3DDB9      ; Upload tilemap

; Set source for uploading decompressed data
C3D518:  LDY #$C000      ; 7E/C000
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         RTS

; Unpack and upload graphics and tilemaps for dense clouds
C3D522:  JSR C3D439      ; Upload font GFX
         JSR C3D6B1      ; Unpack map, GFX
         JSR C3D6D6      ; Upload sprites
         JSR C3D66B      ; Pal numbers loc
         JSR C3D552      ; Convert M7 GFX A
         JSR C3D543      ; Insert tilemap A
         JSR C3D634      ; Upload M7 map A
         JSR C3D66B      ; Pal numbers loc
         JSR C3D562      ; Convert M7 GFX B
         JSR C3D543      ; Insert tilemap B
         JMP C3D64C      ; Upload M7 map B

; Assemble half of tilemap for dense clouds
C3D543:  JSR C3D686      ; Set ptrs loc
         LDX #$FC1A      ; Tiles loc
         STX $F1         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $F3         ; Set src HB
         JMP C3D706      ; Build map

; Add 4bpp graphics to Mode 7 map (first 128 tiles)
C3D552:  STZ $E4         ; Pal index LB
         STZ $E5         ; Pal index HB
         LDA #$80        ; Tiles: 128
         STA $ED         ; Set counter
         LDX #$9800      ; Source LBs
         LDA #$7F        ; Source HB
         JMP C3D74F      ; Convert GFX

; Add 4bpp graphics to Mode 7 map (last 128 tiles)
C3D562:  LDX #$0080      ; Index: 128
         STX $E4         ; Set pal index
         LDA #$80        ; Tiles: 128
         STA $ED         ; Set counter
         LDX #$A800      ; Source LBs
         LDA #$7F        ; Source HB
         JMP C3D74F      ; Convert GFX

; Unpack and upload graphics and tilemaps for grassfield scenes
C3D573:  JSR C3D439      ; Upload font GFX
         JSR C3D694      ; Unpack map, GFX
         JSR C3D6D6      ; Upload sprites
         JMP C3D582      ; Upload M7 map

; Unpack and upload graphics and tilemaps for second-last airship scene
C3D57F:  JSR C3D694      ; Unpack map, GFX
C3D582:  JSR C3D664      ; Pal numbers loc
         JSR C3D552      ; Convert M7 GFX A
         JSR C3D59B      ; Insert tilemap A
         JSR C3D634      ; Upload M7 map A
         JSR C3D664      ; Pal numbers loc
         JSR C3D562      ; Convert M7 GFX B
         JSR C3D59B      ; Insert tilemap B
         JSR C3D64C      ; Upload M7 map B
         RTL

; Assemble half of grassfield tilemap
C3D59B:  JSR C3D675      ; Set ptrs loc
         LDX #$DD3A      ; Tiles loc
         STX $F1         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $F3         ; Set src HB
         JMP C3D706      ; Build map

; Unpack and upload graphics and tilemaps for boat scene
C3D5AA:  JSR C3D439      ; Upload font GFX
         JSR C3D694      ; Unpack map, GFX
         JSR C3D6D6      ; Upload sprites
         JSR C3D664      ; Pal numbers loc
         JSR C3D552      ; Convert M7 GFX A
         JSR C3D5CB      ; Insert tilemap A
         JSR C3D634      ; Upload M7 map A
         JSR C3D664      ; Pal numbers loc
         JSR C3D562      ; Convert M7 GFX B
         JSR C3D5CB      ; Insert tilemap B
         JMP C3D64C      ; Upload M7 map B

; Assemble half of tilemap for sea with boat
C3D5CB:  JSR C3D67F      ; Set ptrs loc
         LDX #$2CFA      ; Tiles loc
         STX $F1         ; Set src LBs
         LDA #$7F        ; Bank: 7F
         STA $F3         ; Set src HB
         JMP C3D706      ; Build map

; Unpack and upload graphics and tilemaps for skimming airship scene
C3D5DA:  JSR C3D439      ; Upload font GFX
         JSR C3D694      ; Unpack map, GFX
         JSR C3D6D6      ; Upload sprites
         JSR C3D664      ; Pal numbers loc
         JSR C3D552      ; Convert M7 GFX A
         JSR C3D5FB      ; Insert tilemap A
         JSR C3D634      ; Upload M7 map A
         JSR C3D664      ; Pal numbers loc
         JSR C3D562      ; Convert M7 GFX B
         JSR C3D5FB      ; Insert tilemap B
         JMP C3D64C      ; Upload M7 map B

; Assemble half of tilemap for sea without boat
C3D5FB:  JSR C3D686      ; Set ptrs loc
         LDX #$2CFA      ; Tiles loc
         STX $F1         ; Set src LBs
         LDA #$7F        ; Bank: 7F
         STA $F3         ; Set src HB
         JMP C3D706      ; Build map

; Unpack and upload graphics and tilemaps for final airship scene
C3D60A:  JSR C3D6B1      ; Unpack map, GFX
         JSR C3D66B      ; Pal numbers loc
         JSR C3D552      ; Convert M7 GFX A
         JSR C3D625      ; Insert tilemap
         JSR C3D634      ; Upload M7 map A
         JSR C3D66B      ; Pal numbers loc
         JSR C3D562      ; Convert M7 GFX B
         JSR C3D625      ; Insert tilemap B
         JMP C3D64C      ; Upload M7 map B

; Assemble half of tilemap for final airship scene
C3D625:  JSR C3D675      ; Set ptrs loc
         LDX #$041A      ; Tiles loc
         STX $F1         ; Set src LBs
         LDA #$7F        ; Bank: 7F
         STA $F3         ; Set src HB
         JMP C3D706      ; Build map

; Upload upper half of Mode 7 map
C3D634:  LDY #$B800      ; 7F/B800
         STY $E7         ; Set src LBs
         LDA #$7F        ; Bank: 7F
         STA $E9         ; Set src HB
         STZ $ED         ; Attrib LB: 0
         STZ $EE         ; Attrib HB: 0
         LDY #$4000      ; Bytes: 16384
         STY $EB         ; Set data size
         LDY #$0000      ; VRAM pointer
         JMP C3DDB9      ; Upload map

; Upload lower half of Mode 7 map
C3D64C:  LDY #$B800      ; 7F/B800
         STY $E7         ; Set src LBs
         LDA #$7F        ; Bank: 7F
         STA $E9         ; Set src HB
         STZ $ED         ; Attrib LB: 0
         STZ $EE         ; Attrib HB: 0
         LDY #$4000      ; Bytes: 16384
         STY $EB         ; Set data size
         LDY #$2000      ; VRAM pointer
         JMP C3DDB9      ; Upload map

; Set palette index table location for plains or sea
C3D664:  LDX #$F9E1      ; Ptrs loc LBs
         LDA #$CF        ; Ptrs loc HB
         BRA C3D670      ; Set pointer

; Set palette index table location for sky scenes
C3D66B:  LDX #$F969      ; CF/F969
         LDA #$CF        ; Bank: CF
C3D670:  STX $91         ; Set loc LBs
         STA $93         ; Set loc HB
         RTS

; Set tilemap pointer table location for final scenes
C3D675:  LDX #$FAE9      ; CF/FAE9
         LDA #$CF        ; Bank: CF
C3D67A:  STX $F7         ; Set loc LBs
         STA $F9         ; Set loc HB
         RTS

; Set tilemap pointer table location for boat scene
C3D67F:  LDX #$FAC9      ; Table loc LBs
         LDA #$CF        ; Table loc HB
         BRA C3D67A      ; Set pointer

; Set tilemap pointer table location for skimming airship and cloud scenes
C3D686:  LDX #$FAA9      ; Table loc LBs
         LDA #$CF        ; Table loc HB
         BRA C3D67A      ; Set pointer

; Set tilemap pointer table location for sideview airship scene
C3D68D:  LDX #$FB09      ; Table loc LBs
         LDA #$CF        ; Table loc HB
         BRA C3D67A      ; Set pointer

; Unpack credits scene GFX and maps, move ocean and grassfield GFX
C3D694:  JSR C3D6CE      ; Unpack data
         LDX #$141A      ; 7F/141A
         STX $E7         ; Set src LBs
         LDA #$7F        ; Bank: 7F
         STA $E9         ; Set src HB
         LDY #$9800      ; 7F/9800
         STY $EB         ; Set dst LBs
         LDA #$7F        ; Bank: 7F
         STA $ED         ; Set dst HB
         LDY #$18E0      ; Bytes: 6368
         STY $EF         ; Set data size
         JMP C3D6EE      ; Move data

; Unpack credits scene GFX and tilemaps, move cloud and BG airship GFX
C3D6B1:  JSR C3D6CE      ; Unpack data
         LDX #$ED3A      ; 7E/ED3A
         STX $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         LDY #$9800      ; 7F/9800
         STY $EB         ; Set dst LBs
         LDA #$7F        ; Bank: 7F
         STA $ED         ; Set dst HB
         LDY #$0EE0      ; Bytes: 3808
         STY $EF         ; Set data size
         JMP C3D6EE      ; Move data

; Unpack non-font graphics for credits scenes
C3D6CE:  LDY #$568F      ; Source LBs
         LDA #$D9        ; Source HB
         JMP C3DD61      ; Unpack data

; Upload non-font sprite graphics for credits scenes
C3D6D6:  LDY #$C000      ; 7E/C000
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         LDY #$17BA      ; Bytes: 6074
         STY $EB         ; Set data size
         STZ $ED         ; Attrib LB: 0
         STZ $EE         ; Attrib HB: 0
         LDY #$6000      ; VRAM pointer
         JMP C3DDB9      ; Upload data

; Relocate decompressed data, adjust attributes if tilemap
C3D6EE:  STZ $F1         ; ...
         STZ $F2         ; ...
         REP #$20        ; 16-bit A
         LDY $00         ; Index: 0
C3D6F6:  LDA [$E7],Y     ; Unpacked data
         CLC             ; ...
         ADC $F1         ; ...
         STA [$EB],Y     ; Put in buffer
         INY             ; Index +1
         INY             ; Index +1
         CPY $EF         ; Past range?
         BNE C3D6F6      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Add a 128x64 tilemap to Mode 7 map
C3D706:  TDC             ; Clear A
         TAY             ; Index: 0
C3D708:  REP #$20        ; 16-bit A
         LDA [$F7],Y     ; Src index
         TAX             ; Save in X
         INY             ; Index +1
         INY             ; Index +1
         LDA [$F7],Y     ; Dst index
         STA $E7         ; Memorize it
         INY             ; Index +1
         INY             ; Index +1
         SEP #$20        ; 8-bit A
         PHY             ; Save index
         TXY             ; Src index
         JSR C3D723      ; Copy 32x32 map
         PLY             ; Restore index
         CPY #$0020      ; Done 8 maps?
         BNE C3D708      ; Loop if not
         RTS

; Add a 32x32 tilemap to Mode 7 map
C3D723:  PHB             ; Save DB
         LDA #$7F        ; Bank: 7F
         PHA             ; Put on stack
         PLB             ; Set DB to 7F
         LDA #$20        ; Rows: 32
         STA $E0         ; Set counter
C3D72C:  LDA #$20        ; Columns: 32
         STA $E1         ; Set counter
         LDX $E7         ; Dst index
C3D732:  LDA [$F1],Y     ; Tile number
         STA $B800,X     ; Add to M7 map
         INY             ; Src index +1
         INX             ; Dst index +1
         INX             ; Dst index +1
         DEC $E1         ; One less column
         BNE C3D732      ; Loop till last
         REP #$21        ; 16-bit A; C-
         LDA $E7         ; Dst index
         ADC #$0100      ; +128 tiles
         STA $E7         ; Save changes
         SEP #$20        ; 8-bit A
         DEC $E0         ; One less row
         BNE C3D72C      ; Loop till last
         PLB             ; Restore DB
         RTS

; Add 4bpp tile graphics to Mode 7 map
C3D74F:  STA $E9         ; Set src HB
         STX $E7         ; Set src LBs
         PHB             ; Save DB
         LDA #$7F        ; Bank: 7F
         PHA             ; Put on stack
         PLB             ; Set DB to 7F
         TDC             ; Clear A
         TAX             ; Dst index: 0
C3D75A:  LDA #$08        ; Rows left: 8
         STA $E6         ; Set counter

; Fork: Load 8-pixel row
C3D75E:  REP #$20        ; 16-bit A
         LDY #$0010      ; Src index: 16
         LDA [$E7]       ; Planes A & B
         STA $F1         ; Memorize them
         LDA [$E7],Y     ; Planes C & D
         STA $EF         ; Memorize them
         TDC             ; ...
         SEP #$20        ; 8-bit A

; Fork: Convert each pixel in row
C3D76E:  LDY #$0008      ; Pixels: 8
C3D771:  TDC             ; Clear A
         ASL $F0         ; Get plane D
         ROL A           ; Roll into A
         ASL $EF         ; Get plane C
         ROL A           ; Roll into A
         ASL $F2         ; Get plane B
         ROL A           ; Roll into A
         ASL $F1         ; Get plane A
         ROL A           ; Roll into A
         AND #$0F        ; Blank pixel?
         BEQ C3D792      ; Branch if so
         STA $E0         ; Save 0-15 color
         PHY             ; Save pixels left
         LDY $E4         ; Palette index
         LDA [$91],Y     ; Palette number
         PLY             ; Pixels left
         ASL A           ; Palette x2
         ASL A           ; Palette x4
         ASL A           ; Palette x8
         ASL A           ; Palette x16
         AND #$F0        ; ...
         ORA $E0         ; Add 0-15 color
C3D792:  STA $B801,X     ; Set map pixel
         INX             ; Dst index +1
         INX             ; Dst index +1
         DEY             ; One less pixel
         BNE C3D771      ; Loop till last

; Fork: Do tile's next row
C3D79A:  LDY $E7         ; Source
         INY             ; Source +1
         INY             ; Source +1
         STY $E7         ; Save changes
         DEC $E6         ; One less row
         BNE C3D75E      ; Loop till last

; Fork: Do next tile
C3D7A4:  REP #$20        ; 16-bit A
         INC $E4         ; Pal index +1
         LDA $E7         ; Source
         CLC             ; Prepare ADC
         ADC #$0010      ; Skip done data
         STA $E7         ; Save changes
         TDC             ; Clear A
         SEP #$20        ; 8-bit A
         DEC $ED         ; One less tile
         BNE C3D75A      ; Loop till last
         PLB             ; Restore DB
         RTS

; Handle credits timing for sideview airship scene
C3D7B9:  PHB             ; Save DB
         LDA #$C3        ; ...
         PHA             ; ...
         PLB             ; ...
         LDY $CF         ; Scene timer
         CPY #$003C      ; 60?
         BNE C3D7C8      ; Exit if not
         JSR C3DA03      ; Init producer
C3D7C8:  PLB             ; Restore DB
         SEC             ; Set to requeue
         RTS

; Handle credits timing for aerial-view airship scene
C3D7CB:  PHB             ; Save DB
         LDA #$C3        ; ...
         PHA             ; ...
         PLB             ; ...
         LDY $CF         ; Scene timer
         CPY #$000A      ; 10?
         BNE C3D7DC      ; Branch if not
         JSR C3DA0E      ; Init director
         BRA C3D816      ; Exit

; Fork: Main programmer
C3D7DC:  CPY #$01AE      ; 430?
         BNE C3D7E6      ; Branch if not
         JSR C3DA19      ; Init sprites
         BRA C3D816      ; Exit

; Fork: Graphic director (page 1)
C3D7E6:  CPY #$0352      ; 850?
         BNE C3D7F0      ; Branch if not
         JSR C3DA24      ; Init sprites
         BRA C3D816      ; Exit

; Fork: Graphic director (page 2)
C3D7F0:  CPY #$04F6      ; 1270?
         BNE C3D7FA      ; Branch if not
         JSR C3DA2F      ; Init sprites
         BRA C3D816      ; Exit

; Fork: Music
C3D7FA:  CPY #$069A      ; 1690?
         BNE C3D804      ; Branch if not
         JSR C3DA3A      ; Init sprites
         BRA C3D816      ; Exit

; Fork: Image design
C3D804:  CPY #$083E      ; 2110?
         BNE C3D80E      ; Branch if not
         JSR C3DA45      ; Init sprites
         BRA C3D816      ; Exit

; Fork: Battle planner
C3D80E:  CPY #$09E2      ; 2530?
         BNE C3D816      ; Exit if not
         JSR C3DA50      ; Init sprites
C3D816:  PLB             ; Restore DB
         SEC             ; Set to requeue
         RTS

; Handle credits timing for boat scene
C3D819:  PHB             ; Save DB
         LDA #$C3        ; ...
         PHA             ; ...
         PLB             ; ...
         LDY $CF         ; Scene timer
         CPY #$000A      ; 10?
         BNE C3D82A      ; Branch if not
         JSR C3DA5B      ; Init field pln
         BRA C3D846      ; Exit

; Fork: Event planner
C3D82A:  CPY #$01AE      ; 430?
         BNE C3D834      ; Branch if not
         JSR C3DA66      ; Init sprites
         BRA C3D846      ; Exit

; Fork: Effect programmer
C3D834:  CPY #$0352      ; 850?
         BNE C3D83E      ; Branch if not
         JSR C3DA71      ; Init sprites
         BRA C3D846      ; Exit

; Fork: Battle programmer
C3D83E:  CPY #$04F6      ; 1270?
         BNE C3D846      ; Exit if not
         JSR C3DA7C      ; Init sprites
C3D846:  PLB             ; Restore DB
         SEC             ; Set to requeue
         RTS

; Handle credits timing for skimming airship scene
C3D849:  PHB             ; Save DB
         LDA #$C3        ; ...
         PHA             ; ...
         PLB             ; ...
         LDY $CF         ; Scene timer
         CPY #$000A      ; 10?
         BNE C3D85A      ; Branch if not
         JSR C3DA87      ; Init sound prg
         BRA C3D894      ; Exit

; Fork: Effect graphic designer
C3D85A:  CPY #$01AE      ; 430?
         BNE C3D864      ; Branch if not
         JSR C3DA92      ; Init sprites
         BRA C3D894      ; Exit

; Fork: Field graphic designer (page 1)
C3D864:  CPY #$0352      ; 850?
         BNE C3D86E      ; Branch if not
         JSR C3DA9D      ; Init sprites
         BRA C3D894      ; Exit

; Fork: Field graphic designer (page 2)
C3D86E:  CPY #$04F6      ; 1270?
         BNE C3D878      ; Branch if not
         JSR C3DAA8      ; Init sprites
         BRA C3D894      ; Exit

; Fork: Field graphic designer (page 3)
C3D878:  CPY #$069A      ; 1690?
         BNE C3D882      ; Branch if not
         JSR C3DAB3      ; Init sprites
         BRA C3D894      ; Exit

; Fork: Monster graphic designer
C3D882:  CPY #$083E      ; 2110?
         BNE C3D88C      ; Branch if not
         JSR C3DABE      ; Init sprites
         BRA C3D894      ; Exit

; Fork: Object graphic designer
C3D88C:  CPY #$09E2      ; 2530?
         BNE C3D894      ; Exit if not
         JSR C3DAC9      ; Init sprites
C3D894:  PLB             ; Restore DB
         SEC             ; Set to requeue
         RTS

; Handle credits timing for frontview airship scene
C3D897:  PHB             ; Save DB
         LDA #$C3        ; ...
         PHA             ; ...
         PLB             ; ...
         LDY $CF         ; Scene timer
         CPY #$000A      ; 10?
         BNE C3D8A8      ; Branch if not
         JSR C3DAD4      ; Init sound eng
         BRA C3D8E2      ; Exit

; Fork: Sound effect (page 1)
C3D8A8:  CPY #$01AE      ; 430?
         BNE C3D8B2      ; Branch if not
         JSR C3DADF      ; Init sprites
         BRA C3D8E2      ; Exit

; Fork: Sound effect (page 2)
C3D8B2:  CPY #$0352      ; 850?
         BNE C3D8BC      ; Branch if not
         JSR C3DAEA      ; Init sprites
         BRA C3D8E2      ; Exit

; Fork: Remake planner, translator
C3D8BC:  CPY #$04F6      ; 1270?
         BNE C3D8C6      ; Branch if not
         JSR C3DAF5      ; Init sprites
         BRA C3D8E2      ; Exit

; Fork: System engineer (page 1)
C3D8C6:  CPY #$069A      ; 1690?
         BNE C3D8D0      ; Branch if not
         JSR C3DB00      ; Init sprites
         BRA C3D8E2      ; Exit

; Fork: System engineer (page 2)
C3D8D0:  CPY #$083E      ; 2110?
         BNE C3D8DA      ; Branch if not
         JSR C3DB0B      ; Init sprites
         BRA C3D8E2      ; Exit

; Fork: Executive producer
C3D8DA:  CPY #$09E2      ; 2530?
         BNE C3D8E2      ; Exit if not
         JSR C3DB16      ; Init sprites
C3D8E2:  PLB             ; Restore DB
         SEC             ; Set to requeue
         RTS

; Handle credits timing for aerial-view plains scene
C3D8E5:  PHB             ; Save DB
         LDA #$C3        ; ...
         PHA             ; ...
         PLB             ; ...
         LDY $CF         ; Scene timer
         CPY #$00F0      ; 240?
         BNE C3D8F6      ; Branch if not
         JSR C3DB21      ; Init test coord
         BRA C3D930      ; Exit

; Fork: Special thanks (page 1)
C3D8F6:  CPY #$02D0      ; 720?
         BNE C3D900      ; Branch if not
         JSR C3DB2C      ; Init sprites
         BRA C3D930      ; Exit

; Fork: Special thanks (page 2)
C3D900:  CPY #$04B0      ; 1200?
         BNE C3D90A      ; Branch if not
         JSR C3DB37      ; Init sprites
         BRA C3D930      ; Exit

; Fork: Special thanks (page 3)
C3D90A:  CPY #$0690      ; 1680?
         BNE C3D914      ; Branch if not
         JSR C3DB42      ; Init sprites
         BRA C3D930      ; Exit

; Fork: Special thanks (page 4)
C3D914:  CPY #$0870      ; 2160?
         BNE C3D91E      ; Branch if not
         JSR C3DB4D      ; Init sprites
         BRA C3D930      ; Exit

; Fork: Special thanks (page 5)
C3D91E:  CPY #$0A50      ; 2640?
         BNE C3D928      ; Branch if not
         JSR C3DB58      ; Init sprites
         BRA C3D930      ; Exit

; Fork: Special thanks (page 6)
C3D928:  CPY #$0C30      ; 3120?
         BNE C3D930      ; Exit if not
         JSR C3DB63      ; Init sprites
C3D930:  PLB             ; Restore DB
         SEC             ; Set to requeue
         RTS

; Handle credits timing for rearview airship scene
C3D933:  PHB             ; Save DB
         LDA #$C3        ; ...
         PHA             ; ...
         PLB             ; ...
         LDY $CF         ; Scene timer
         CPY #$003C      ; 60?
         BNE C3D944      ; Branch if not
         JSR C3DB6E      ; Init thanks_p7
         BRA C3D96A      ; Exit

; Fork: Special thanks (page 8)
C3D944:  CPY #$01E0      ; 480?
         BNE C3D94E      ; Branch if not
         JSR C3DB79      ; Init sprites
         BRA C3D96A      ; Exit

; Fork: Special thanks (page 9)
C3D94E:  CPY #$0384      ; 900?
         BNE C3D958      ; Branch if not
         JSR C3DB84      ; Init sprites
         BRA C3D96A      ; Exit

; Fork: Special thanks (page 10)
C3D958:  CPY #$0528      ; 1320?
         BNE C3D962      ; Branch if not
         JSR C3DB8F      ; Init sprites
         BRA C3D96A      ; Exit

; Fork: Special thanks (page 11)
C3D962:  CPY #$06CC      ; 1740?
         BNE C3D96A      ; Exit if not
         JSR C3DB9A      ; Init sprites
C3D96A:  PLB             ; Restore DB
         SEC             ; Set to requeue
         RTS

; Build credits' OAM table for sideview airship scene
C3D96D:  LDX #$9DC0      ; Source LBs
         LDA #$C2        ; Source HB
         LDY #$0004      ; Sprites: 1
         JSR C3D9F1      ; Do position
         LDX #$9C44      ; Source LBs
         LDA #$C2        ; Source HB
         LDY #$0008      ; Sprites: 2
         JMP C3D9FA      ; Do staff

; Build credits' OAM table for aerial-view airship scene
C3D983:  LDX #$9DC4      ; Source LBs
         LDA #$C2        ; Source HB
         LDY #$0028      ; Sprites: 10
         JSR C3D9F1      ; Do positions
         LDX #$9C4C      ; Source LBs
         LDA #$C2        ; Source HB
         LDY #$0060      ; Sprites: 24
         JMP C3D9FA      ; Do staff

; Build credits' OAM table for boat scene
C3D999:  LDX #$9DEC      ; Source LBs
         LDA #$C2        ; Source HB
         LDY #$0018      ; Sprites: 6
         JSR C3D9F1      ; Do positions
         LDX #$9CAC      ; Source LBs
         LDA #$C2        ; Source HB
         LDY #$0040      ; Sprites: 16
         JMP C3D9FA      ; Do staff

; Build credits' OAM table for skimming airship scene
C3D9AF:  LDX #$9E04      ; Source LBs
         LDA #$C2        ; Source HB
         LDY #$0020      ; Sprites: 8
         JSR C3D9F1      ; Do positions
         LDX #$9CEC      ; Source LBs
         LDA #$C2        ; Source HB
         LDY #$0064      ; Sprites: 25
         JMP C3D9FA      ; Do staff

; Build credits' OAM table for frontview airship scene
C3D9C5:  LDX #$9E24      ; Source LBs
         LDA #$C2        ; Source HB
         LDY #$0024      ; Sprites: 9
         JSR C3D9F1      ; Do positions
         LDX #$9D50      ; Source LBs
         LDA #$C2        ; Source HB
         LDY #$0070      ; Sprites: 28
         JMP C3D9FA      ; Do staff

; Build credits' OAM table for aerial-view plains scene
C3D9DB:  LDX #$9E48      ; Source LBs
         LDA #$C2        ; Source HB
         LDY #$00E4      ; Sprites: 57
         JMP C3D9F1      ; Build OAM

; Build credits' OAM table for rearview airship scene
C3D9E6:  LDX #$9F2C      ; Source LBs
         LDA #$C2        ; Source HB
         LDY #$006C      ; Sprites: 27
         JMP C3D9F1      ; ...

; Build OAM table for scene's small credits strings; set source
C3D9F1:  STX $4A         ; Set src LBs
         STA $4C         ; Set src HB
         STY $4D         ; Set range end
         JMP C3DBC8      ; Build tables

; Build OAM table for scene's large credits strings; set source
C3D9FA:  STX $4A         ; Set src LBs
         STA $4C         ; Set src HB
         STY $4D         ; Set range end
         JMP C3DBE8      ; Build tables

; Initialize credits for producer
C3DA03:  LDY #$000C      ; Sprites: 3
         LDX #$9894      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for director
C3DA0E:  LDY #$0014      ; Sprites: 5
         LDX #$98A0      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for main programmer
C3DA19:  LDY #$0018      ; Sprites: 6
         LDX #$98B4      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for graphic director, page 1
C3DA24:  LDY #$0018      ; Sprites: 6
         LDX #$98CC      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for graphic director, page 2
C3DA2F:  LDY #$0018      ; Sprites: 6
         LDX #$98E4      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for music
C3DA3A:  LDY #$000C      ; Sprites: 3
         LDX #$98FC      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for image design
C3DA45:  LDY #$0010      ; Sprites: 4
         LDX #$9908      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for battle planner
C3DA50:  LDY #$0018      ; Sprites: 6
         LDX #$9918      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for field planner
C3DA5B:  LDY #$0020      ; Sprites: 8
         LDX #$9930      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for event planner
C3DA66:  LDY #$0018      ; Sprites: 6
         LDX #$9950      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for effect programmer
C3DA71:  LDY #$0018      ; Sprites: 6
         LDX #$9968      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for battle programmer
C3DA7C:  LDY #$0010      ; Sprites: 4
         LDX #$9980      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for sound programmer
C3DA87:  LDY #$0010      ; Sprites: 4
         LDX #$9990      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for effect graphic designer
C3DA92:  LDY #$0014      ; Sprites: 5
         LDX #$99A0      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for field graphic designer, page 1
C3DA9D:  LDY #$0024      ; Sprites: 9
         LDX #$99B4      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for field graphic designer, page 2
C3DAA8:  LDY #$0024      ; Sprites: 9
         LDX #$99D8      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for field graphic designer, page 3
C3DAB3:  LDY #$0024      ; Sprites: 9
         LDX #$99FC      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for monster graphic designer
C3DABE:  LDY #$0014      ; Sprites: 5
         LDX #$9A20      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for object graphic designer
C3DAC9:  LDY #$0014      ; Sprites: 5
         LDX #$9A34      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for sound engineer
C3DAD4:  LDY #$0010      ; Sprites: 4
         LDX #$9A48      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for sound effect, page 1
C3DADF:  LDY #$0018      ; Sprites: 6
         LDX #$9A58      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for sound effect, page 2
C3DAEA:  LDY #$0018      ; Sprites: 6
         LDX #$9A70      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for remake planner and translator
C3DAF5:  LDY #$0024      ; Sprites: 9
         LDX #$9A88      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for system engineer, page 1
C3DB00:  LDY #$0018      ; Sprites: 6
         LDX #$9AAC      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for system engineer, page 2
C3DB0B:  LDY #$0018      ; Sprites: 6
         LDX #$9AC4      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for executive producer
C3DB16:  LDY #$0018      ; Sprites: 6
         LDX #$9ADC      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for test coordinator
C3DB21:  LDY #$0028      ; Sprites: 10
         LDX #$9AF4      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for special thanks, page 1
C3DB2C:  LDY #$0028      ; Sprites: 10
         LDX #$9B1C      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for special thanks, page 2
C3DB37:  LDY #$0024      ; Sprites: 9
         LDX #$9B44      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for special thanks, page 3
C3DB42:  LDY #$0020      ; Sprites: 8
         LDX #$9B68      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for special thanks, page 4
C3DB4D:  LDY #$0018      ; Sprites: 6
         LDX #$9B88      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for special thanks, page 5
C3DB58:  LDY #$0014      ; Sprites: 5
         LDX #$9BA0      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for special thanks, page 6
C3DB63:  LDY #$0024      ; Sprites: 9
         LDX #$9BB4      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for special thanks, page 7
C3DB6E:  LDY #$0018      ; Sprites: 6
         LDX #$9BD8      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for special thanks, page 8
C3DB79:  LDY #$0018      ; Sprites: 6
         LDX #$9BF0      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for special thanks, page 9
C3DB84:  LDY #$0014      ; Sprites: 5
         LDX #$9C08      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for special thanks, page 10
C3DB8F:  LDY #$0014      ; Sprites: 5
         LDX #$9C1C      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; Init sprites

; Initialize credits for special thanks, page 11
C3DB9A:  LDY #$0014      ; Sprites: 5
         LDX #$9C30      ; Source LBs
         LDA #$C2        ; Source HB
         JMP C3DBA5      ; ...

; Initialize sprites for current credits strings
C3DBA5:  STY $FA         ; Set src range
         STX $F7         ; Set src LBs
         STA $F9         ; Set src HB
         LDY $00         ; Index: 0
C3DBAD:  REP #$20        ; 16-bit A
         LDA [$F7],Y     ; Anim table ptr
         TAX             ; Save in X
         INY             ; Index +1
         INY             ; Index +1
         LDA [$F7],Y     ; Position
         STA $60         ; Memorize it
         SEP #$20        ; 8-bit A
         PHY             ; Save index
         TXY             ; Anim table ptr
         JSR C3DC14      ; Init sprite
         PLY             ; Table index
         INY             ; Index +1
         INY             ; Index +1
         CPY $FA         ; Past range?
         BNE C3DBAD      ; Loop if not
         SEC             ; ...
         RTS

; Build OAM table for scene's small credits strings
C3DBC8:  LDY $00         ; Index: 0
C3DBCA:  JSR C3DC08      ; Get attribs
         REP #$20        ; 16-bit A
         LDA [$4A],Y     ; Text ptr
         TAX             ; Put in X
         INY             ; Index +1
         INY             ; Index +1
         LDA [$4A],Y     ; Dest LBs
         STA $E7         ; Memorize it
         INY             ; Index +1
         INY             ; Index +1
         PHY             ; Save index
         LDY $E7         ; Dest LBs
         SEP #$20        ; 8-bit A
         JSR C3DCBC      ; Build table
         PLY             ; Pointer index
         CPY $4D         ; Past range?
         BNE C3DBCA      ; Loop if not
         RTS

; Build OAM table for scene's large credits strings
C3DBE8:  LDY $00         ; Index: 0
C3DBEA:  JSR C3DC0E      ; Get attribs
         REP #$20        ; 16-bit A
         LDA [$4A],Y     ; Source LBs
         TAX             ; Save in X
         INY             ; Index +1
         INY             ; Index +1
         LDA [$4A],Y     ; Dest LBs
         STA $E7         ; Save them
         INY             ; Index +1
         INY             ; Index +1
         PHY             ; Save index
         LDY $E7         ; Dest LBs
         SEP #$20        ; 8-bit A
         JSR C3DCD1      ; Build table
         PLY             ; Pointer index
         CPY $4D         ; Past range?
         BNE C3DBEA      ; Loop if not
         RTS

; Set attribute complements for small credits
C3DC08:  LDX #$0B00      ; ADR+, pal 5
         STX $F1         ; Save attribs
         RTS

; Set attribute complements for large credits
C3DC0E:  LDX #$0900      ; ADR+, pal 4
         STX $F1         ; Set attribs
         RTS

; Initialize sprite for current credit string
C3DC14:  STY $F1         ; Save anim ptr
         STZ $AF         ; Request fade-in
         LDA #$00        ; Min slot: 0
         LDY #C3DC44     ; C3/DC44
         JSR C31173      ; Queue anim fn
         REP #$20        ; 16-bit A
         LDA $F1         ; Anim table ptr
         STA $7E32C9,X   ; Set sprite's
         LDA #$01A4      ; Frames: 420
         STA $7E3349,X   ; Set hide delay
         SEP #$20        ; 8-bit A
         LDA #$7E        ; Bank: 7E
         STA $7E35CA,X   ; Set ptr HB
         LDA $60         ; X position
         STA $7E33CA,X   ; Set sprite's
         LDA $61         ; Y position
         STA $7E344A,X   ; Set sprite's
         RTS

; Animate credit string
C3DC44:  TAX             ; Index mode
         JMP (C3DC48,X)  ; Handle mode

; Jump table for the above
C3DC48:  dw C3DC4C       ; Initialize sprite
         dw C3DC84       ; Sustain sprite

; Mode 0: Initialize sprite
C3DC4C:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         LDA $344A,X     ; Sprite's Y
         CLC             ; Prepare ADC
         ADC #$20        ; Go 32 px down
         STA $344A,X     ; Save changes
         REP #$20        ; 16-bit A
         LDA #$FF80      ; V-Spd: -0.5 px
         STA $3549,X     ; Set sprite's
         STZ $34C9,X     ; H-Speed: 0
         SEP #$20        ; 8-bit A
         JSR C31206      ; Set pose timer
         LDA $AF         ; Handled fade-in?
         BNE C3DC84      ; Skip it if so
         PHB             ; Save DB
         LDA #$00        ; Bank: 00
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         LDA $B4         ; Text on clouds?
         BNE C3DC7C      ; Use blue if so
         JSR C3C703      ; Fade-in: White
         BRA C3DC7F      ; Skip a line
C3DC7C:  JSR C3C72A      ; Fade-in: Blue
C3DC7F:  LDA #$01        ; Mark as handled
         STA $AF         ; Allow fade-out
         PLB             ; Restore DB

; Mode 1: Sustain sprite
C3DC84:  LDX $2D         ; Queue index
         LDY $3349,X     ; Mode expired?
         BEQ C3DCA9      ; Delete if so
         CPY #$0164      ; 356?
         BNE C3DC96      ; Scroll if not
         STZ $3549,X     ; V-Speed LB: 0
         STZ $354A,X     ; V-Speed HB: 0
C3DC96:  CPY #$0080      ; 128?
         BEQ C3DCAB      ; Fade if so
C3DC9B:  JSR C3DEC0      ; Scroll & OAM
         LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         DEC $3349,X     ; Timer -1
         SEP #$20        ; 8-bit A
         SEC             ; Set to requeue
         RTS             ; Exit
C3DCA9:  CLC             ; Set to dequeue
         RTS

; Fork: Set to fade all text
C3DCAB:  LDA $AF         ; Already set?
         BEQ C3DC9B      ; Skip if so
         STZ $AF         ; Mark as handled
         PHB             ; Save DB
         LDA #$00        ; Bank: 00
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         JSR C3C6DC      ; Trigger fade
         PLB             ; Restore DB
         BRA C3DC9B      ; Scroll & OAM

; Build OAM table for small credit string
C3DCBC:  JSR C3DD31      ; Set OAM tbl ptr
         JSR C3DD25      ; Set size, rel X
C3DCC2:  JSR C3DD02      ; Set a char's OAM
         BCC C3DCD0      ; Exit if no more
         LDA $E0         ; Relative X
         CLC             ; Prepare ADC
         ADC #$08        ; Go 8 px right
         STA $E0         ; Save changes
         BRA C3DCC2      ; Do next letter
C3DCD0:  RTS

; Build OAM table for large credit string
C3DCD1:  JSR C3DD31      ; Set OAM tbl ptr
         JSR C3DD25      ; Set size, rel X
C3DCD7:  TDC             ; ...
         LDA [$E7]       ; At terminator?
         BEQ C3DD01      ; Exit if so
         STA $E3         ; Save letter
         LDA $E0         ; Relative X
         ORA #$80        ; Add 16x16 flag
         STA [$EB],Y     ; Set for letter
         INY             ; Index +1
         TDC             ; Relative Y: 0
         STA [$EB],Y     ; Set letter's
         INY             ; Index +1
         TDC             ; ...
         LDA $E3         ; Letter
         REP #$21        ; 16-bit A; C-
         ADC $F1         ; Add attribs
         STA [$EB],Y     ; Set attribs
         INC $E7         ; Letter +1
         INY             ; Index +1
         INY             ; Index +1
         SEP #$20        ; 8-bit A
         LDA $E0         ; Relative X
         CLC             ; Prepare ADC
         ADC #$08        ; Go 8 px right
         STA $E0         ; Save changes
         BRA C3DCD7      ; Do next letter
C3DD01:  RTS

; Build OAM for small credit letter, clear Carry if terminator
C3DD02:  TDC             ; ...
         LDA [$E7]       ; At terminator?
         BEQ C3DD23      ; Exit if so
         STA $E3         ; Save letter
         LDA $E0         ; Relative X
         STA [$EB],Y     ; Set letter's
         INY             ; Index +1
         TDC             ; Relative Y: 0
         STA [$EB],Y     ; Set letter's
         INY             ; Index +1
         TDC             ; ...
         LDA $E3         ; Letter
         REP #$21        ; 16-bit A; C-
         ADC $F1         ; Add attribs
         STA [$EB],Y     ; Set attribs
         INC $E7         ; Letter +1
         INY             ; Index +1
         INY             ; Index +1
         SEP #$20        ; 8-bit A
         SEC             ; End: No
         RTS             ; Exit
C3DD23:  CLC             ; End: Yes
         RTS

; Set credit string's size and reset relative X position
C3DD25:  LDY $00         ; Index: 0
         STA [$EB],Y     ; Set size
         INY             ; Index +1
         STZ $E0         ; Rel X: 0
         STZ $EF         ; No use...
         STZ $F0         ; No use...
         RTS

; Set OAM table pointer for credit string, compute string size
C3DD31:  STX $E7         ; Set src LBs
         LDA #$C2        ; Bank: C2
         STA $E9         ; Set src HB
         STY $EB         ; Set dst LBs
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set dst HB
         REP #$21        ; 16-bit A; C-
         LDA $EB         ; Dest LBs
         ADC #$0003      ; +3 bytes
         STA [$EB]       ; Set OAM ptr
         INC $EB         ; Dst LBs +1
         INC $EB         ; Dst LBs +1
         SEP #$20        ; 8-bit A
         LDA #$FE        ; Time: Infinite
         STA [$EB]       ; Set pose timer
         INC $EB         ; Dst LBs +1
         LDY $00         ; Letter: 1st
         TYX             ; Tile count: 0
C3DD55:  LDA [$E7],Y     ; Letter
         INY             ; Point to next
         CMP #$00        ; Terminator?
         BEQ C3DD5F      ; Exit if so
         INX             ; Tile count +1
         BRA C3DD55      ; Do next letter
C3DD5F:  TXA             ; String size
         RTS

; Decompress data
C3DD61:  STY $F3         ; Set src LBs
         STA $F5         ; Set src HB
         LDY #$C000      ; 7E/C000
         STY $F6         ; Set dst LBs
         LDA #$7E        ; Bank: 7E
         STA $F8         ; Set dst HB
         JSL $C2FF6D     ; Unpack data
         RTS

; Clear VRAM
C3DD73:  REP #$20        ; 16-bit A
         TDC             ; $0000
         STA $2116       ; Set VRAM ptr
         TAY             ; Counter: 0
C3DD7A:  STA $2118       ; Zero VRAM word
         INY             ; Counter +1
         CPY #$8000      ; Done all VRAM?
         BNE C3DD7A      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Convert and upload graphics for range of font characters
C3DD86:  STY $2116       ; Set VRAM ptr
         TDC             ; Clear A
         TAY             ; Index: 0
         REP #$20        ; 16-bit A
C3DD8D:  LDX #$0008      ; 8-px rows: 8
C3DD90:  LDA [$E7],Y     ; 8 px, 2 planes
         STA $2118       ; Save in VRAM
         INY             ; Index +1
         INY             ; Index +1
         DEX             ; One less row
         BNE C3DD90      ; Loop till last
         STZ $2118       ; Planes 1C, 1D
         STZ $2118       ; Planes 2C, 2D
         STZ $2118       ; Planes 3C, 3D
         STZ $2118       ; Planes 4C, 4D
         STZ $2118       ; Planes 5C, 5D
         STZ $2118       ; Planes 6C, 6D
         STZ $2118       ; Planes 7C, 7D
         STZ $2118       ; Planes 8C, 8D
         CPY $EB         ; More tiles?
         BNE C3DD8D      ; Loop if so
         SEP #$20        ; 8-bit A
         RTS

; Upload data manually, adjust attributes if tilemap
C3DDB9:  REP #$20        ; 16-bit A
         TYA             ; VRAM pointer
         STA $2116       ; To register
         TDC             ; Clear A
         TAY             ; Index: 0
C3DDC1:  LDA [$E7],Y     ; Source data
         CLC             ; Prepare ADC
         ADC $ED         ; Add attribs
         STA $2118       ; Save in VRAM
         INY             ; Index +1
         INY             ; Index +1
         CPY $EB         ; Past range?
         BNE C3DDC1      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Build Mode 7 matrix tables for HDMA
C3DDD2:  PHB             ; Save DB
         LDA #$00        ; Bank: 00
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         REP #$20        ; 16-bit A

; Fork: Define scale dividend
C3DDD9:  LDA $C3         ; Dividend index
         JSR C3DE76      ; Signed dividend
         STA $E0         ; ...
         STA $EB         ; Memorize it
         LDA $E0         ; Positive?
         BPL C3DDEA      ; Branch if so
         EOR #$FFFF      ; Invert value
         INC A           ; Add 1
C3DDEA:  STA $E0         ; ...
         LSR A           ; Halve it
         STA $CB         ; Save dividend

; Fork: Define shear dividend
C3DDEF:  LDA $C3         ; Dividend index
         JSR C3DE7A      ; Signed dividend
         STA $E0         ; ...
         STA $ED         ; Memorize it
         LDA $E0         ; Positive?
         BPL C3DE00      ; Branch if so
         EOR #$FFFF      ; Invert value
         INC A           ; Add 1
C3DE00:  STA $E0         ; ...
         LSR A           ; Halve it
         STA $C9         ; Save dividend

; Fork: Define matrices A and D for two scanlines
C3DE05:  LDY #$01BE      ; Scanline: Last
         LDA $C5         ; Base divisor
         STA $E7         ; Memorize it
C3DE0C:  LDA $CB         ; Scale dividend
         STA $4204       ; To register
         SEP #$20        ; 8-bit A
         LDA $E8         ; Map factor HB
         STA $4206       ; Set divisor
         NOP
         NOP
         NOP
         NOP
         NOP
         REP #$20        ; 16-bit A
         LDA $EB         ; Positive mod?
         BPL C3DE2C      ; Branch if so
         LDA $4214       ; Quotient
         EOR #$FFFF      ; Invert value
         INC A           ; Add 1
         BRA C3DE2F      ; Skip a line
C3DE2C:  LDA $4214       ; Quotient
C3DE2F:  STA $0602,Y     ; Set line 1
         STA $0604,Y     ; Set line 2

; Fork: Define matrices B and C for two scanlines
C3DE35:  LDA $C9         ; Shear dividend
         STA $4204       ; To register
         SEP #$20        ; 8-bit A
         LDA $E8         ; Map factor HB
         STA $4206       ; Set divisor
         NOP
         NOP
         REP #$20        ; 16-bit A
         LDA $E7         ; Matrix divisor
         SEC             ; Prepare SBC
         SBC $C7         ; Deduct "angle"
         STA $E7         ; Save changes
         LDA $ED         ; Positive mod?
         BPL C3DE59      ; Branch if so
         LDA $4214       ; Quotient
         EOR #$FFFF      ; Invert it
         INC A           ; Add 1
         BRA C3DE5C      ; Skip a line
C3DE59:  LDA $4214       ; Quotient
C3DE5C:  STA $07C4,Y     ; Set line B1
         STA $07C6,Y     ; Set line B2
         EOR #$FFFF      ; Invert it
         INC A           ; Add 1
         STA $0986,Y     ; Set line C1
         STA $0988,Y     ; Set line C2
         DEY             ; Index -1
         DEY             ; Index -1
         DEY             ; Index -1
         DEY             ; Index -1
         BPL C3DE0C      ; Loop if > 0
         SEP #$20        ; 8-bit A
         PLB             ; Restore DB
         RTS

; Load animation modifier
C3DE76:  CLC             ; Prepare ADC
         ADC #$0040      ; Index +64
C3DE7A:  AND #$00FF      ; Clear HB
         ASL A           ; Double it
         TAX             ; Index it
         LDA $C2FC6D,X   ; Modifier
         RTS

; Animate linearly moving temporary sprite
C3DE84:  TAX             ; Index mode
         JMP (C3DE88,X)  ; Handle mode

; Jump table for the above
C3DE88:  dw C3DE8C       ; Initialize timer
         dw C3DE94       ; Sustain sprite

; Mode 0: Initialize timer
C3DE8C:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         JSR C31206      ; Set pose timer

; Mode 1: Sustain sprite
C3DE94:  LDX $2D         ; Queue index
         LDY $3349,X     ; Timer expired?
         BEQ C3DEA9      ; Delete if so
         JSR C3DEC0      ; Scroll & OAM
         LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         DEC $3349,X     ; Timer -1
         SEP #$20        ; 8-bit A
         SEC             ; Set to requeue
         RTS             ; Exit
C3DEA9:  CLC             ; Set to dequeue
         RTS

; Animate regular permanent sprite
C3DEAB:  TAX             ; Index mode
         JMP (C3DEAF,X)  ; Handle mode

; Jump table for the above
C3DEAF:  dw C3DEB3       ; Initialize timer
         dw C3DEBB       ; Sustain sprite

; Mode 0: Initialize timer
C3DEB3:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         JSR C31206      ; Set pose timer

; Mode 1: Sustain sprite
C3DEBB:  JSR C3DEC0      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS

; Scroll sprite and define OAM
C3DEC0:  LDX $2D         ; Queue index
         REP #$21        ; 16-bit A; C-
         LDA $33C9,X     ; Fractional X
         ADC $34C9,X     ; Add H-Speed
         STA $33C9,X     ; Save changes
         LDA $3449,X     ; Fractional Y
         CLC             ; Prepare ADC
         ADC $3549,X     ; Add V-Speed
         STA $3449,X     ; Save changes
         SEP #$20        ; ...
         JSR C31221      ; Define OAM
         RTS

; Animate true actor name or "And you"
C3DEDD:  STA $E0         ; Save mode
         LDA $47         ; At 2nd actor?
         BNE C3DEE9      ; Delete if so
         LDA $E0         ; Anim mode
         TAX             ; Index it
         JMP (C3DEEB,X)  ; Handle mode
C3DEE9:  CLC             ; Set to dequeue
         RTS

; Jump table for the above
C3DEEB:  dw C3DEFF       ; Initialize sprite
         dw C3DF13       ; Refresh sprite
         dw C3DF1B       ; Set to scroll up
         dw C3DF13       ; Refresh sprite
         dw C3DF23       ; Stop scrolling
         dw C3DF13       ; Refresh sprite
         dw C3DF2A       ; Set to scroll up
         dw C3DF13       ; Refresh sprite
         dw C3DEFD       ; Delete sprite

; Mode 8: Delete sprite
C3DEFD:  CLC             ; Set to dequeue
         RTS

; Mode 0: Initialize sprite
C3DEFF:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         REP #$20        ; 16-bit A
         STZ $3549,X     ; V-Speed: 0
         LDA $85         ; Scroll delay
         STA $3349,X     ; Set mode timer
         SEP #$20        ; 8-bit A
         JSR C31206      ; Set pose timer

; Modes 1, 3, 5: Refresh sprite
C3DF13:  JSR C3DF4B      ; Mode timer -1
         JSR C3DEC0      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS

; Mode 2: Set to scroll upward 2.5s
C3DF1B:  LDY #$FFC0      ; V-Spd: -0.25 px
         LDX #$0096      ; Frames: 150
         BRA C3DF32      ; Set spd, timer

; Mode 4: Stop scrolling
C3DF23:  LDY $00         ; V-Speed: 0
         LDX #$00F0      ; Frames: 240
         BRA C3DF32      ; Set spd, timer

; Mode 6: Set to scroll upward 5s
C3DF2A:  LDY #$FFC0      ; V-Spd: -0.25 px
         LDX #$012C      ; Frames: 300
         BRA C3DF32      ; ...

; Fork: Change V-Speed and mode timer
C3DF32:  STY $E7         ; Save V-Speed
         STX $E9         ; Save timer
         LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         LDA $E7         ; V-Speed
         STA $3549,X     ; Set sprite's
         LDA $E9         ; Mode timer
         STA $3349,X     ; Set sprite's
         SEP #$20        ; 8-bit A
         INC $3649,X     ; Mode +1
         BRA C3DF13      ; Scroll & OAM

; Decrease animation timer, advance mode if expired
C3DF4B:  LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         LDA $3349,X     ; Timer expired?
         BNE C3DF59      ; Branch if not
         INC $3649,X     ; Mode +1
         BRA C3DF5C      ; Skip a line
C3DF59:  DEC $3349,X     ; Timer -1
C3DF5C:  SEP #$20        ; 8-bit A
         RTS

; Draw, center, and set to upload actor's pseudonym
C3DF5F:  LDY $00         ; 1st: Terra
C3DF61:  STY $EB         ; Save slot
         REP #$20        ; 16-bit A
         TYA             ; Actor slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C36969,X  ; Actor's address
         TAY             ; Index it
         SEP #$20        ; 8-bit A
         LDA $0000,Y     ; Actor in slot
         CMP $28         ; Matches ours?
         BEQ C3DF99      ; Proceed if so
         REP #$21        ; ...
         LDA #$0025      ; ...
         ADC $E7         ; ...
         STA $E7         ; ...
         SEP #$20        ; ...
         LDY $EB         ; Actor slot
         INY             ; Actor slot +1
         CPY #$0010      ; Done all 16?
         BNE C3DF61      ; Loop if not

; Fork: Default to "??????" (Gogo, Umaro)
C3DF89:  LDX $00         ; Dst index: 0
         LDA.B #!ques    ; Char: "?"
C3DF8D:  STA $7E9E89,X   ; Add to string
         INX             ; Index +1
         CPX #$0006      ; Done 6 chars?
         BNE C3DF8D      ; Loop if not
         BRA C3DFA9      ; Skip alt case

; Fork: Load actor's name
C3DF99:  LDX $00         ; Dst index: 0
C3DF9B:  LDA $0002,Y     ; Letter
         STA $7E9E89,X   ; Add to string
         INY             ; Src index +1
         INX             ; Dst index +1
         CPX #$0006      ; Done 6 chars?
         BNE C3DF9B      ; Loop if not
C3DFA9:  JSR C3DFB3      ; Center name
         JSR C3A611      ; Build tilemap
         JSR C3A63B      ; Load graphics
         RTS

; Center BG3 camera on actor's pseudonym
C3DFB3:  LDX $00         ; Letter: 1st
         STZ $E0         ; Width LB: 0
         STZ $E1         ; Width HB: 0
C3DFB9:  TDC             ; Clear A
         LDA $7E9E89,X   ; Letter
         CMP #$FF        ; Terminator?
         BEQ C3DFD7      ; Branch if so
         PHX             ; Save index
         SEC             ; Prepare SBC
         SBC #$60        ; Use field format
         TAX             ; Index it
         LDA $C48FC0,X   ; Letter width
         CLC             ; Prepare ADC
         ADC $E0         ; Add to total
         STA $E0         ; Save total
         PLX             ; Letter index
         INX             ; Point to next
         CPX #$0006      ; Done all 6?
         BNE C3DFB9      ; Loop if not
C3DFD7:  REP #$20        ; 16-bit A
         LDA $E0         ; Text width
         LSR A           ; Halve it
         STA $E0         ; Save changes
         LDA #$0080      ; BG3's width / 2
         SEC             ; Prepare SBC
         SBC $E0         ; Subtract text's
         EOR #$FFFF      ; Invert value
         INC A           ; Add one
         STA $3D         ; Set BG3 X-Pos
         SEP #$20        ; 8-bit A
         RTS

; Set to temporarily scroll BG1 westward
C3DFED:  STY $F3         ; Save timer
         LDA #$00        ; Min slot: 0
         LDY #C3E002     ; C3/E002
         JSR C31173      ; Queue anim fn
         REP #$20        ; 16-bit A
         LDA $F3         ; Scroll timer
         STA $7E3349,X   ; Set mode timer
         SEP #$20        ; 8-bit A
         RTS

; Temporarily scroll BG1 westward
C3E002:  LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         LDA $3349,X     ; Timer expired?
         BEQ C3E01E      ; Dequeue if so
         DEC $3349,X     ; Timer -1
         SEP #$20        ; 8-bit A
         LDA $23         ; NMI count
         AND #$03        ; Now 0-3
         BNE C3E01C      ; Pause if > 0
         REP #$20        ; 16-bit A
         INC $35         ; BG1 X-Pos +1
         SEP #$20        ; 8-bit A
C3E01C:  SEC             ; Set to requeue
         RTS             ; Exit
C3E01E:  SEP #$20        ; 8-bit A
         CLC             ; Set to dequeue
         RTS

; Create actor's first and last names
C3E022:  TDC             ; Clear A
         LDA $28         ; Actor
         ASL A           ; x2
         ASL A           ; x4
         STA $E0         ; Memorize it
         LDA $28         ; Actor
         ASL A           ; Double it
         CLC             ; Prepare ADC
         ADC $E0         ; Now x6
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA $C28DE4,X   ; Anim ptr A
         STA $4D         ; Memorize it
         SEP #$20        ; 8-bit A
         LDA $C28DE6,X   ; Name A's X
         STA $53         ; Memorize it
         REP #$20        ; 16-bit A
         LDA $C28DE7,X   ; Anim ptr B
         STA $4F         ; Memorize it
         SEP #$20        ; 8-bit A
         LDA $C28DE9,X   ; Name B's X
         STA $54         ; Memorize it
         JSR C3E08F      ; Queue A's anim
         REP #$20        ; 16-bit A
         LDA $4D         ; Anim table ptr
         STA $7E32C9,X   ; Set name A's
         SEP #$20        ; 8-bit A
         LDA #$C2        ; Bank: C2
         STA $7E35CA,X   ; Set ptr HB
         LDA $53         ; X position
         STA $7E33CA,X   ; Set name A's
         LDA #$D0        ; Y: 208
         STA $7E344A,X   ; Set name A's
         JSR C3E08F      ; Queue B's anim
         REP #$20        ; 16-bit A
         LDA $4F         ; Anim table ptr
         STA $7E32C9,X   ; Set name B's
         SEP #$20        ; 8-bit A
         LDA #$C2        ; Bank: C2
         STA $7E35CA,X   ; Set ptr HB
         LDA $54         ; X position
         STA $7E33CA,X   ; Set name B's
         LDA #$D0        ; Y: 208
         STA $7E344A,X   ; Set name B's
         RTS

; Queue true actor name or "And you"
C3E08F:  LDA #$01        ; Min slot: 8
         LDY #C3DEDD     ; C3/DEDD
         JSR C31173      ; Queue anim fn
         RTS

; Create "And you"
C3E098:  JSR C3E08F      ; Queue anim fn
         REP #$20        ; 16-bit A
         LDA #$F8AB      ; Anim table ptr
         STA $7E32C9,X   ; Set sprite's
         SEP #$20        ; 8-bit A
         LDA #$CF        ; Bank: CF
         STA $7E35CA,X   ; Set ptr HB
         LDA #$68        ; X: 104
         STA $7E33CA,X   ; Set sprite's
         LDA #$D0        ; Y: 208
         STA $7E344A,X   ; Set sprite's
         RTS

; Initialize font, BG, and register data for actor scene
C3E0B9:  STA $28         ; Set actor slot
         JSL $D4CE8C     ; Init registers
         JSR C36A3C      ; Clear BG3 A
         JSR C36A28      ; Clear BG2 A
         LDA #$C3        ; Src HB
         LDY #$3049      ; To BG pal 0
         LDX #C310F4     ; Src LBs
         JSR C30F8E      ; BGP0: Black
         LDA #$C3        ; Src HB
         LDY #$3069      ; To BG pal 1
         LDX #C310F4     ; C3/10F4
         JSR C30F8E      ; BGP1: Black
         LDA #$C3        ; Src HB
         LDY #$3089      ; To BG pal 2
         LDX #C310F4     ; Src LBs
         JSR C30F8E      ; BGP2: Black
         LDA #$C3        ; Src HB
         LDY #$30E9      ; To BG pal 5
         LDX #C310F4     ; Src LBs
         JSR C30F8E      ; BGP5: Black
         LDA #$C3        ; Src HB
         LDY #$3109      ; To BG pal 6
         LDX #C310F4     ; Src LBs
         JSR C30F8E      ; BGP6: Black
         LDA #$C3        ; Src HB
         LDY #$3149      ; To OBJ pal 0
         LDX #C310F4     ; Src LBs
         JSR C30F8E      ; OBP0: Black
         LDA #$C3        ; Src HB
         LDY #$3169      ; To OBJ pal 1
         LDX #C310F4     ; Src LBs
         JSR C30F8E      ; OBP1: Black
         LDA #$C3        ; Src HB
         LDY #$31C9      ; To OBJ pal 4
         LDX #C310F4     ; Src LBs
         JSR C30F8E      ; OBP4: Black
         JSR C3EE74      ; Load big font
         JMP C3EE90      ; And BG GFX/map

; Create and upload text for actor scene, unblank screen
C3E123:  STZ $47         ; Erase name: N
         JSR C3E897      ; Create "as"
         LDA #$2C        ; Palette 3
         STA $29         ; No use...
         JSR C3DF5F      ; Create alias
         LDA #$01        ; CGRAM: Freeze
         TRB $45         ; Set NMI flag
         JSR C314AC      ; Upload alias
         LDA #$01        ; CGRAM: Refresh
         TSB $45         ; Set NMI flag
         JSR C3E022      ; Create true name
C3E13D:  JSR C3EF21      ; Queue BG1+BG3a
         INC $26         ; Scene mode +1
         JMP C3C675      ; Set brightness

; Set to fade BG elements for actor scene (also final airship's)
C3E145:  LDA #$C3        ; C3/10F4
         STA $ED         ; Set src HB
         LDA #$04        ; Slowness: 4
         LDY #$30E9      ; To BG pal 5
         STY $E7         ; ...
         LDX #C310F4     ; Black palette
         STX $EB         ; ...
         JSR C30FAA      ; Do tabletop
         LDA #$C3        ; ...
         STA $ED         ; ...
         LDA #$04        ; Slowness: 4
         LDY #$3109      ; To BG pal 6
         STY $E7         ; ...
         LDX #C310F4     ; Black palette
         STX $EB         ; ...
         JSR C30FAA      ; Do overlay
C3E16B:  LDA #$C3        ; C3/10F4
         STA $ED         ; Set src HB
         LDA #$04        ; Slowness: 4
         LDY #$3069      ; To BG pal 1
         STY $E7         ; ...
         LDX #C310F4     ; Black palette
         STX $EB         ; ...
         JSR C30FAA      ; Do book, etc.
         LDA #$C3        ; ...
         STA $ED         ; ...
         LDA #$04        ; Slowness: 4
         LDY #$3089      ; To BG pal 2
         STY $E7         ; ...
         LDX #C310F4     ; Black palette
         STX $EB         ; ...
         JSR C30FAA      ; Do bones, etc.
         RTS

; Set to fade in BG elements for actor scene
C3E192:  LDA #$C2        ; Bank: C2
         STA $ED         ; Set src HB
         LDA #$02        ; Slowness: 2
         LDY #$3069      ; To BG pal 1
         STY $E7         ; ...
         LDX #$967C      ; C2/967C
         STX $EB         ; ...
         JSR C30FAA      ; Do book, etc.
         LDA #$C2        ; ...
         STA $ED         ; ...
         LDA #$02        ; Slowness: 2
         LDY #$3089      ; To BG pal 2
         STY $E7         ; ...
         LDX #$969C      ; C2/969C
         STX $EB         ; ...
         JSR C30FAA      ; Do bones, etc.
         LDA #$C2        ; ...
         STA $ED         ; ...
         LDA #$02        ; Slowness: 2
         LDY #$30E9      ; To BG pal 5
         STY $E7         ; ...
         LDX #$96DC      ; C2/96DC
         STX $EB         ; ...
         JSR C30FAA      ; Do tabletop
         LDA #$C2        ; ...
         STA $ED         ; ...
         LDA #$02        ; Slowness: 2
         LDY #$3109      ; To BG pal 6
         STY $E7         ; ...
         LDX #$96FC      ; C2/96FC
         STX $EB         ; ...
         JSR C30FAA      ; Do overlay
         RTS

; Set to fade in actor's pseudonym and "as"
C3E1DF:  LDA #$C2        ; Bank: C2
         STA $ED         ; Set src HB
         LDA #$04        ; Slowness: 4
         LDY #$3049      ; To BG pal 0
         STY $E7         ; ...
         LDX #$9754      ; C2/9754
         STX $EB         ; ...
         JSR C30FAA      ; Handle name
         LDA #$C2        ; ...
         STA $ED         ; ...
         LDA #$04        ; Slowness: 4
         LDY #$3169      ; To OBJ pal 1
         STY $E7         ; ...
         LDX #$9754      ; C2/9754
         STX $EB         ; ...
         JSR C30FAA      ; Handle "as"
         RTS

; Set to scroll and fade actor alias, fade "as", fade in true name
C3E206:  STZ $CF         ; Scroll timer LB
         STZ $D0         ; Scroll timer HB
         LDY #$00F0      ; Frames: 240
         STY $64         ; Set scroll limit
         LDA #$00        ; Min slot: 0
         LDY #C3D1B6     ; C3/D1B6
         JSR C31173      ; Queue scroll fn
         JSR C3E241      ; Fade pseudonym
         LDA #$C3        ; ...
         STA $ED         ; ...
         LDA #$04        ; Slowness: 4
         LDY #$3169      ; To OBJ pal 1
         STY $E7         ; ...
         LDX #C310F4     ; Black palette
         STX $EB         ; ...
         JSR C30FAA      ; Fade "as"
C3E22D:  LDA #$C2        ; Bank: C2
         STA $ED         ; Set src HB
         LDA #$04        ; Slowness: 4
         LDY #$3149      ; To OBJ pal 0
         STY $E7         ; ...
         LDX #$9754      ; C2/9754
         STX $EB         ; ...
         JSR C30FAA      ; Fade in true name
         RTS

; Set to fade background palette 0
C3E241:  LDA #$C3        ; C3/10F4
         STA $ED         ; Set src HB
         LDA #$04        ; Slowness: 4
         LDY #$3049      ; To BG pal 0
         STY $E7         ; ...
         LDX #C310F4     ; Black palette
         STX $EB         ; ...
         JSR C30FAA      ; Queue fade-out
         RTS

; Set to fade sprite palette 0
C3E255:  LDA #$C3        ; C3/10F4
         STA $ED         ; Set src HB
         LDA #$04        ; Slowness: 4
         LDY #$3149      ; To OBJ pal 0
         STY $E7         ; ...
         LDX #C310F4     ; Black palette
         STX $EB         ; ...
         JSR C30FAA      ; Queue fade-out
         RTS

; Set to return to event script
C3E269:  LDA #$FF        ; Null value
         STA $26         ; Next: Exit
         RTS

; 28: Start Shadow's scene
C3E26E:  LDA #$03        ; Actor: Shadow
         JSR C3E0B9      ; Init BGs/font
         JSR C3EF48      ; Upload apple
         JSR C3E192      ; Fade in BGs
         JSR C3E28A      ; Fade in apple
         JSR C3E83F      ; Scroll table
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for alias
         JSR C3E9B3      ; Create apple
         JMP C3E123      ; Create text

; Set to fade in non-glint sprites on table
C3E28A:  LDA #$C2        ; Bank: C2
         STA $ED         ; Set src HB
         LDA #$02        ; Slowness: 2
         LDY #$31C9      ; To OBJ pal 4
         STY $E7         ; ...
         LDX #$9774      ; C2/9774
         STX $EB         ; ...
         JSR C30FAA      ; Queue fade-in
         RTS

; Set to fade sprite palette 4
C3E29E:  LDA #$C3        ; C3/10F4
         STA $ED         ; Set src HB
         LDA #$04        ; Slowness: 4
         LDY #$31C9      ; To OBJ pal 4
         STY $E7         ; ...
         LDX #C310F4     ; Black palette
         STX $EB         ; ...
         JSR C30FAA      ; Queue fade-out
         RTS

; 29: Fade in "Shadow as"
C3E2B2:  LDY $20         ; Delay expired?
         BNE C3E2C0      ; Exit if not
         INC $26         ; Next: C3/E2C1
         JSR C3E1DF      ; Queue fade-in
         LDY #$00F0      ; Switch delay
         STY $20         ; Set for names
C3E2C0:  RTS

; 2A: Switch Shadow's names
C3E2C1:  LDY $20         ; Delay expired?
         BNE C3E2CF      ; Exit if not
         INC $26         ; Next: C3/E2D0
         JSR C3E206      ; Switch names
         LDY #$0168      ; Fade/Pan delay
         STY $20         ; Set for below
C3E2CF:  RTS

; 2B: Fade all but Shadow's name
C3E2D0:  LDY $20         ; Delay expired?
         BNE C3E2E6      ; Exit if not
         LDA #$38        ; C3/E2E7
         STA $26         ; Next: Fd name
         LDY #$0078      ; Fade delay
         STY $20         ; Set for name
         JSR C3E145      ; Fade BGs
         JSR C3E29E      ; Fade apple
         JSR C3E845      ; Scroll table
C3E2E6:  RTS

; 38: Fade actor's true name
C3E2E7:  LDY $20         ; Delay expired?
         BNE C3E2F7      ; Exit if not
         LDY #$0078      ; Frames: 120
         STY $20         ; Set exit delay
         LDA #$01        ; C3/C5D4
         STA $26         ; Next: Exit
         JSR C3E255      ; Queue fade-out
C3E2F7:  RTS

; 32: Start Cyan's scene
C3E2F8:  LDA #$02        ; Actor: Cyan
         JSR C3E0B9      ; Init BGs/font
         JSR C3EF68      ; Draw sword; GFX
         JSR C3E192      ; Fade in BGs
         JSR C3E468      ; Fade in glint
         LDY #$FFB8      ; X: -72 = 440
         STY $35         ; Set BG1 X-Pos
         JSR C3E839      ; Scroll table
         JSR C3EC36      ; Queue glints
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for alias
         JMP C3E123      ; Create text

; 33: Fade in "Cyan as"
C3E319:  LDY $20         ; Delay expired?
         BNE C3E327      ; Exit if not
         INC $26         ; Next: C3/E328
         JSR C3E1DF      ; Queue fade-in
         LDY #$00F0      ; Switch delay
         STY $20         ; Set for names
C3E327:  RTS

; 34: Switch Cyan's names
C3E328:  LDY $20         ; Delay expired?
         BNE C3E336      ; Exit if not
         INC $26         ; Next: C3/E337
         JSR C3E206      ; Switch names
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3E336:  RTS

; 35: Fade all but Cyan's name
C3E337:  LDY $20         ; Delay expired?
         BNE C3E34A      ; Exit if not
         LDA #$38        ; C3/E2E7
         STA $26         ; Next: Fd name
         LDY #$0078      ; Fade delay
         STY $20         ; Set for name
         JSR C3E145      ; Fade BGs
         JSR C3E29E      ; Fade glint
C3E34A:  RTS

; 40: Start Edgar and Sabin's scene
C3E34B:  LDA #$04        ; Actor: Edgar
         JSR C3E0B9      ; Init BGs/font
         JSR C3EF7E      ; Upload coin
         JSR C3E192      ; Fade in BGs
         JSR C3E28A      ; Fade in coin
         JSR C3EC24      ; Queue coin fn
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for name
         JMP C3E123      ; Create text

; 41: Fade in "Edgar as"
C3E364:  LDY $20         ; Delay expired?
         BNE C3E372      ; Exit if not
         INC $26         ; Next: C3/E373
         JSR C3E1DF      ; Queue fade-in
         LDY #$00F0      ; Switch delay
         STY $20         ; Set for alias
C3E372:  RTS

; 42: Switch Edgar's names
C3E373:  LDY $20         ; Delay expired?
         BNE C3E381      ; Exit if not
         INC $26         ; Next: C3/E382
         JSR C3E206      ; Switch names
         LDY #$00F0      ; Intro delay
         STY $20         ; Set for Sabin
C3E381:  RTS

; 43: Show Sabin's name, fade Edgar's
C3E382:  LDY $20         ; Delay expired?
         BNE C3E3A1      ; Exit if not
         LDY $00         ; ...
         STY $3F         ; BG3 Y-Pos: 0
         LDA #$05        ; Actor: Sabin
         STA $28         ; Set actor slot
         JSR C3E897      ; Create "as"
         JSR C3E255      ; Fade Edgar
         JSR C3DF5F      ; Create Sabin
         JSR C3E1DF      ; Fade in Sabin
         INC $26         ; Next: C3/E3A2
         LDY #$0078      ; Removal delay
         STY $20         ; Set for Edgar
C3E3A1:  RTS

; 44: Delete Edgar's name
C3E3A2:  LDY $20         ; Delay expired?
         BNE C3E3B1      ; Exit if not
         LDA #$01        ; Erase name: Y
         STA $47         ; Set sprite flag
         INC $26         ; Next: C3/E3B2
         LDY #$00B4      ; Switch delay
         STY $20         ; Set for Sabin
C3E3B1:  RTS

; 45: Switch Sabin's names
C3E3B2:  LDY $20         ; Delay expired?
         BNE C3E3CC      ; Exit if not
         LDA #$4F        ; C3/E3CD
         STA $26         ; Next: Fade BG
         LDY #$00B4      ; Frames: 180
         STY $20         ; Set fade delay
         STZ $47         ; Erase name: N
         LDY #$0014      ; Frames: 20
         STY $85         ; Set scroll delay
         JSR C3E022      ; Create true name
         JSR C3E206      ; Switch names
C3E3CC:  RTS

; 4F: Fade all but Sabin's name
C3E3CD:  LDY $20         ; Delay expired?
         BNE C3E3E0      ; Exit if not
         LDA #$38        ; C3/E2E7
         STA $26         ; Next: Fd name
         LDY #$0078      ; Fade delay
         STY $20         ; Set for name
         JSR C3E145      ; Fade BGs
         JSR C3E29E      ; Fade coin
C3E3E0:  RTS

; 3C: Start Mog's scene
C3E3E1:  LDA #$0A        ; Actor: Mog
         JSR C3E0B9      ; Init BGs/font
         JSR C3EFA2      ; Draw tree; GFX
         JSR C3E192      ; Fade in BGs
         JSR C3E28A      ; Fade in sprites
         JSR C3E83F      ; Scroll table
         JSR C3EA24      ; Create sprites
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for name
         JMP C3E123      ; Create text

; 3D: Fade in "Mog as"
C3E3FD:  LDY $20         ; Delay expired?
         BNE C3E40B      ; Exit if not
         INC $26         ; Next: C3/E40C
         JSR C3E1DF      ; Queue fade-in
         LDY #$00F0      ; Switch delay
         STY $20         ; Set for names
C3E40B:  RTS

; 3E: Switch Mog's names
C3E40C:  LDY $20         ; Delay expired?
         BNE C3E41A      ; Exit if not
         INC $26         ; Next: C3/E41B
         JSR C3E206      ; Switch names
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3E41A:  RTS

; 3F: Fade all but Mog's name
C3E41B:  LDY $20         ; Delay expired?
         BNE C3E431      ; Exit if not
         LDA #$38        ; C3/E2E7
         STA $26         ; Next: Fd name
         LDY #$0078      ; Fade delay
         STY $20         ; Set for name
         JSR C3E145      ; Fade BGs
         JSR C3E29E      ; Fade sprites
         JSR C3E845      ; Scroll table
C3E431:  RTS

; 46: Start Gogo's scene
C3E432:  LDA #$0C        ; Actor: Gogo
         JSR C3E0B9      ; Init BGs/font
         JSR C3EFB8      ; Draw helmet; eye
         JSR C3E192      ; Fade in BGs
         JSR C3E839      ; Scroll table
         JSR C3E9E4      ; Create pink eye
         LDA #$02        ; Min slot: 16
         LDY #C3E49F     ; C3/E49F
         JSR C31173      ; Queue eye fn
         LDA #$B4        ; Eye delay
         LDA $7E3349,X   ; Bug: LDA -> STA
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for name
         JMP C3E123      ; Create text

; 47: Fade in "Gogo as"
C3E459:  LDY $20         ; Delay expired?
         BNE C3E467      ; Exit if not
         INC $26         ; Next: C3/E47C
         JSR C3E1DF      ; Queue fade-in
         LDY #$00F0      ; Switch delay
         STY $20         ; Set for nameS
C3E467:  RTS

; Set to fade in glint on table object
C3E468:  LDA #$C2        ; Bank: C2
         STA $ED         ; Set src HB
         LDA #$01        ; Slowness: 1
         LDY #$31C9      ; To OBJ pal 4
         STY $E7         ; ...
         LDX #$955C      ; C2/955C
         STX $EB         ; ...
         JSR C30FAA      ; Queue fade-in
         RTS

; 48: Switch Gogo's names
C3E47C:  LDY $20         ; Delay expired?
         BNE C3E48A      ; Exit if not
         INC $26         ; Next: C3/E48B
         JSR C3E206      ; Switch names
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3E48A:  RTS

; 49: Fade all but Gogo's name
C3E48B:  LDY $20         ; Delay expired?
         BNE C3E49E      ; Exit if not
         LDA #$38        ; C3/E2E7
         STA $26         ; Next: Fd name
         LDY #$0078      ; Fade delay
         STY $20         ; Set for name
         JSR C3E145      ; Fade BGs
         JSR C3E29E      ; Fade eye
C3E49E:  RTS

; Animate eye in Gogo's helmet
C3E49F:  TAX             ; Index mode
         JMP (C3E4A3,X)  ; Handle mode

; Jump table for Gogo's eye
C3E4A3:  dw C3E4AB       ; Wait
         dw C3E4BA       ; Fade in eye
         dw C3E4AB       ; Wait
         dw C3E4DF       ; Fade out eye

; Modes 0 and 2: Wait
C3E4AB:  LDX $2D         ; Queue index
         LDA $3349,X     ; Timer expired?
         BNE C3E4B5      ; Branch if not
         INC $3649,X     ; Mode +1
C3E4B5:  DEC $3349,X     ; Timer -1
         SEC             ; Set to requeue
         RTS

; Mode 1: Fade in eye
C3E4BA:  PHB             ; Save DB
         LDA #$00        ; ...
         PHA             ; ...
         PLB             ; ...
         LDA #$C2        ; Bank: C2
         STA $ED         ; Set src HB
         LDA #$01        ; Slowness: 1
         LDY #$31C9      ; To OBJ pal 4
         STY $E7         ; ...
         LDX #$957C      ; C2/957C
         STX $EB         ; ...
         JSR C30FAA      ; Queue fade-in
         PLB             ; Restore DB
         LDX $2D         ; Queue index
         LDA #$3C        ; Delay: 60
         STA $3349,X     ; Set fade-out's
         INC $3649,X     ; Mode +1
         SEC             ; Set to requeue
         RTS

; Mode 3: Fade out eye
C3E4DF:  PHB             ; Save DB
         LDA #$00        ; ...
         PHA             ; ...
         PLB             ; ...
         LDA #$C3        ; C3/10F4
         STA $ED         ; Set src HB
         LDA #$01        ; Slowness: 1
         LDY #$31C9      ; To OBJ pal 4
         STY $E7         ; ...
         LDX #C310F4     ; Black palette
         STX $EB         ; ...
         JSR C30FAA      ; Queue fade
         PLB             ; Restore DB
         CLC             ; Set to dequeue
         RTS

; 50: Start Gau's scene
C3E4FA:  LDA #$0B        ; Actor: Gau
         JSR C3E0B9      ; Init BGs/font
         JSR C3EFCE      ; Draw helmet; face
         JSR C3E192      ; Fade in BGs
         JSR C3E28A      ; Fade in face
         JSR C3E83F      ; Scroll table
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for name
         JMP C3E123      ; Create text

; 51: Fade in "Gau as"
C3E513:  LDY $20         ; Delay expired?
         BNE C3E521      ; Exit if not
         INC $26         ; Next: C3/E522
         JSR C3E1DF      ; Queue fade-in
         LDY #$00F0      ; Switch delay
         STY $20         ; Set for names
C3E521:  RTS

; 52: Switch Gau's names; create face
C3E522:  LDY $20         ; Delay expired?
         BNE C3E533      ; Exit if not
         INC $26         ; Next: C3/E534
         JSR C3E994      ; Create face
         JSR C3E206      ; Switch names
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3E533:  RTS

; 53: Fade all but Gau's name
C3E534:  LDY $20         ; Delay expired?
         BNE C3E54A      ; Exit if not
         LDA #$38        ; C3/E2E7
         STA $26         ; Next: Fd name
         LDY #$0078      ; Fade delay
         STY $20         ; Set for name
         JSR C3E145      ; Fade BGs
         JSR C3E29E      ; Fade face
         JSR C3E845      ; Scroll table
C3E54A:  RTS

; 5A: Start Terra's scene
C3E54B:  LDA #$00        ; Actor: Terra
         JSR C3E0B9      ; Init BGs/font
         JSR C3EFE4      ; Draw glass; GFX
         JSR C3E192      ; Fade in BGs
         JSR C3E468      ; Fade in glint
         JSR C3E83F      ; Scroll table
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for name
         JMP C3E123      ; Create text

; 5B: Fade in "Terra as"
C3E564:  LDY $20         ; Delay expired?
         BNE C3E572      ; Exit if not
         INC $26         ; Next: C3/E573
         JSR C3E1DF      ; Queue fade-in
         LDY #$00F0      ; Switch delay
         STY $20         ; Set for names
C3E572:  RTS

; 5C: Switch Terra's names, create glint
C3E573:  LDY $20         ; Delay expired?
         BNE C3E584      ; Exit if not
         INC $26         ; Next: C3/E585
         JSR C3EA03      ; Create glint
         JSR C3E206      ; Switch names
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3E584:  RTS

; 5D: Fade all but Terra's name
C3E585:  LDY $20         ; Delay expired?
         BNE C3E59B      ; Exit if not
         LDA #$38        ; C3/E2E7
         STA $26         ; Next: Fd name
         LDY #$0078      ; Fade delay
         STY $20         ; Set for name
         JSR C3E145      ; Fade BGs
         JSR C3E29E      ; Fade glint
         JSR C3E845      ; Scroll table
C3E59B:  RTS

; 64: Start Locke and Celes's scene
C3E59C:  LDA #$01        ; Actor: Locke
         JSR C3E0B9      ; Init BGs/font
         JSR C3EFFA      ; Draw bouquet
         JSR C3E192      ; Fade in BGs
         JSR C3E83F      ; Scroll table
         LDY #$FFE0      ; X: -32 = 480
         STY $35         ; Set BG1 X-Pos
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for name
         JMP C3E123      ; Create text

; 65: Fade in "Locke as"
C3E5B7:  LDY $20         ; Delay expired?
         BNE C3E5C5      ; Exit if not
         INC $26         ; Next: C3/E5C6
         JSR C3E1DF      ; Queue fade-in
         LDY #$00F0      ; Switch delay
         STY $20         ; Set for alias
C3E5C5:  RTS

; 66: Switch Locke's names
C3E5C6:  LDY $20         ; Delay expired?
         BNE C3E5D4      ; Exit if not
         INC $26         ; Next: C3/E5D5
         JSR C3E206      ; Switch names
         LDY #$00F0      ; Intro delay
         STY $20         ; Set for Celes
C3E5D4:  RTS

; 67: Show Celes's name, fade Locke's
C3E5D5:  LDY $20         ; Delay expired?
         BNE C3E5F4      ; Exit if not
         LDY $00         ; ...
         STY $3F         ; BG3 Y-Pos: 0
         LDA #$06        ; Actor: Celes
         STA $28         ; Set actor slot
         JSR C3E897      ; Create "as"
         JSR C3E255      ; Fade Locke
         JSR C3DF5F      ; Create Celes
         JSR C3E1DF      ; Fade in Celes
         INC $26         ; Next: C3/E5F5
         LDY #$0078      ; Removal delay
         STY $20         ; Set for Locke
C3E5F4:  RTS

; 68: Delete Locke's name
C3E5F5:  LDY $20         ; Delay expired?
         BNE C3E604      ; Exit if not
         LDA #$01        ; Erase name: Y
         STA $47         ; Set sprite flag
         INC $26         ; Next: C3/E605
         LDY #$00B4      ; Switch delay
         STY $20         ; Set for Celes
C3E604:  RTS

; 69: Switch Celes's names
C3E605:  LDY $20         ; Delay expired?
         BNE C3E61D      ; Exit if not
         INC $26         ; Next: C3/E61E
         LDY #$00B4      ; Frames: 180
         STY $20         ; Set fade delay
         STZ $47         ; Erase name: N
         LDY #$0014      ; Frames: 20
         STY $85         ; Set scroll delay
         JSR C3E022      ; Create true name
         JSR C3E206      ; Switch names
C3E61D:  RTS

; 6A: Fade all but Celes's name
C3E61E:  LDY $20         ; Delay expired?
         BNE C3E634      ; Exit if not
         LDA #$38        ; C3/E2E7
         STA $26         ; Next: Fd name
         LDY #$0078      ; Fade delay
         STY $20         ; Set for name
         JSR C3E145      ; Fade BGs
         JSR C3E29E      ; No sprites...
         JSR C3E845      ; Scroll table
C3E634:  RTS

; 6E: Start Relm's scene
C3E635:  LDA #$08        ; Actor: Relm
         JSR C3E0B9      ; Init BGs/font
         JSR C3F00D      ; Draw brush; GFX
         JSR C3E192      ; Fade in BGs
         JSR C3E468      ; Fade in glint
         JSR C3E83F      ; Scroll table
         JSR C3EC2D      ; Queue glints
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for name
         JMP C3E123      ; Create text

; 6F: Fade in "Relm as"
C3E651:  LDY $20         ; Delay expired?
         BNE C3E65F      ; Exit if not
         INC $26         ; Next: C3/E660
         JSR C3E1DF      ; Queue fade-in
         LDY #$00F0      ; Switch delay
         STY $20         ; Set for names
C3E65F:  RTS

; 70: Switch Relm's names
C3E660:  LDY $20         ; Delay expired?
         BNE C3E66E      ; Exit if not
         INC $26         ; Next: C3/E66F
         JSR C3E206      ; Switch names
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3E66E:  RTS

; 71: Fade all but Relm's name
C3E66F:  LDY $20         ; Delay expired?
         BNE C3E685      ; Exit if not
         LDA #$38        ; C3/E2E7
         STA $26         ; Next: Fd name
         LDY #$0078      ; Fade delay
         STY $20         ; Set for name
         JSR C3E145      ; Fade BGs
         JSR C3E29E      ; Fade glint
         JSR C3E845      ; Scroll table
C3E685:  RTS

; 78: Start Strago's scene
C3E686:  LDA #$07        ; Actor: Strago
         JSR C3E0B9      ; Init BGs/font
         JSR C3F023      ; Draw book
         JSR C3E192      ; Fade in BGs
         JSR C3ED7F      ; Queue book fn
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for name
         JMP C3E123      ; Create text

; 79: Fade in "Strago as"
C3E69C:  LDY $20         ; Delay expired?
         BNE C3E6AA      ; Exit if not
         INC $26         ; Next: C3/E6AB
         JSR C3E1DF      ; Queue fade-in
         LDY #$00F0      ; Switch delay
         STY $20         ; Set for names
C3E6AA:  RTS

; 7A: Switch Strago's names
C3E6AB:  LDY $20         ; Delay expired?
         BNE C3E6B9      ; Exit if not
         INC $26         ; Next: C3/E6BA
         JSR C3E206      ; Switch names
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3E6B9:  RTS

; 7B: Fade all but Strago's name
C3E6BA:  LDY $20         ; Delay expired?
         BNE C3E6CD      ; Exit if not
         LDA #$38        ; C3/E2E7
         STA $26         ; Next: Fd name
         LDY #$0078      ; Fade delay
         STY $20         ; Set for name
         JSR C3E145      ; Fade BGs
         JSR C3E29E      ; No sprites...
C3E6CD:  RTS

; 2D: Start first book scene
C3E6CE:  JSR C3E0B9      ; Init BGs/font
         JSR C3F023      ; Draw book
         JSR C3E192      ; Fade in BGs
         LDY #$02D0      ; Frames: 720
         STY $20         ; Set anim delay
         JMP C3E13D      ; Queue BG1, etc.

; 2E: Animate first book
C3E6DF:  LDY $20         ; Delay expired?
         BNE C3E6ED      ; Exit if not
         INC $26         ; Next: C3/E6EE
         JSR C3ED94      ; Queue book fn
         LDY #$01E0      ; Frames: 480
         STY $20         ; Set wait timer
C3E6ED:  RTS

; 2F: Wait 480 frames
C3E6EE:  LDY $20         ; Delay expired?
         BNE C3E6F9      ; Exit if not
         INC $26         ; Next: C3/E6FA
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3E6F9:  RTS

; 30: Pixelate and fade first book
C3E6FA:  LDY $20         ; Delay expired?
         BNE C3E710      ; Exit if not
         LDA #$38        ; C3/E2E7
         STA $26         ; Next: Exit
         JSR C3E84B      ; Queue mosaic
         LDY #$0078      ; Frames: 120x2
         STY $20         ; Set exit delay
         JSR C3E145      ; Fade BGs
         JSR C3E845      ; Scroll table
C3E710:  RTS

; 4A: Start last book scene
C3E711:  JSR C3E0B9      ; Init BGs/font
         JSR C3F023      ; Draw book
         JSR C3E192      ; Fade in BGs
         JSR C3EDA9      ; Queue book fn
         LDY #$00B4      ; Frames: 180
         STY $20         ; Set wait timer
         STZ $47         ; Erase text: N
         JSR C3E098      ; Create "And you"
         JMP C3E13D      ; Queue BG1, etc.

; 4B: Wait 180 frames
C3E72A:  LDY $20         ; Delay expired?
         BNE C3E735      ; Exit if not
         INC $26         ; Next: C3/E736
         LDY #$00EC      ; Freeze delay
         STY $20         ; Set for book
C3E735:  RTS

; 4C: Stop last book and fade in text
C3E736:  LDY $20         ; Delay expired?
         BNE C3E748      ; Exit if not
         LDA #$01        ; Last page: Y
         STA $99         ; Set book flag
         INC $26         ; Next: C3/E749
         LDY #$016C      ; Frames: 364
         STY $20         ; Set fade delay
         JSR C3E22D      ; Queue fade-in
C3E748:  RTS

; 4D: Pixelate and fade last book
C3E749:  LDY $20         ; Delay expired?
         BNE C3E75C      ; Exit if not
         LDA #$38        ; C3/E2E7
         STA $26         ; Next: Fd text
         JSR C3E84B      ; Queue mosaic
         LDY #$0078      ; Fade delay
         STY $20         ; Set for text
         JSR C3E145      ; Fade BGs
C3E75C:  RTS

; 82: Start Setzer's scene
C3E75D:  LDA #$09        ; Actor: Setzer
         JSR C3E0B9      ; Init BGs/font
         JSR C3F036      ; Upload cards
         JSR C3E192      ; Fade in BGs
         LDA #$C3        ; Pal loc HB
         LDY #$3189      ; To OBJ pal 2
         LDX #C310F4     ; Pal loc LBs
         JSR C30F8E      ; Cards: Black
         LDA #$C2        ; Bank: C2
         STA $ED         ; Set src HB
         LDA #$02        ; Slowness: 2
         LDY #$3189      ; To OBJ pal 2
         STY $E7         ; ...
         LDX #$9774      ; C2/9774
         STX $EB         ; ...
         JSR C30FAA      ; Fade in cards
         JSR C3E839      ; Scroll table
         JSR C3E8E3      ; Create cards
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for alias
         JMP C3E123      ; Create text

; 83: Fade in "Setzer as"
C3E794:  LDY $20         ; Delay expired?
         BNE C3E7A2      ; Exit if not
         INC $26         ; Next: C3/E7A3
         JSR C3E1DF      ; Queue fade-in
         LDY #$00F0      ; Switch delay
         STY $20         ; Set for names
C3E7A2:  RTS

; 84: Switch Setzer's names
C3E7A3:  LDY $20         ; Delay expired?
         BNE C3E7B1      ; Exit if not
         INC $26         ; Next: C3/E7B2
         JSR C3E206      ; Switch names
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3E7B1:  RTS

; 85: Fade background
C3E7B2:  LDY $20         ; Delay expired?
         BNE C3E7C0      ; Exit if not
         INC $26         ; Next: C3/E7C1
         LDY #$0078      ; Fade delay
         STY $20         ; Set for cards
         JSR C3E145      ; Fade BGs
C3E7C0:  RTS

; 86: Fade cards and name
C3E7C1:  LDY $20         ; Delay expired?
         BNE C3E7E4      ; Exit if not
         LDY #$0078      ; Frames: 120
         STY $20         ; Set exit delay
         LDA #$01        ; C3/C5D4
         STA $26         ; Next: Exit
         JSR C3E255      ; Fade name
         LDA #$C3        ; ...
         STA $ED         ; ...
         LDA #$04        ; Slowness: 4
         LDY #$3189      ; To OBJ pal 2
         STY $E7         ; ...
         LDX #C310F4     ; Black palette
         STX $EB         ; ...
         JSR C30FAA      ; Fade cards
C3E7E4:  RTS

; 87: Start Umaro's scene
C3E7E5:  LDA #$0D        ; Actor: Umaro
         JSR C3E0B9      ; Init BGs/font
         JSR C3F072      ; Draw bones; GFX
         JSR C3E192      ; Fade in BGs
         JSR C3E28A      ; Fade in sprites
         JSR C3E83F      ; Scroll table
         JSR C3E8C4      ; Create skull
         JSR C3EA7C      ; Create moogles
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for alias
         JMP C3E123      ; Create text

; 88: Fade in "Umaro as"
C3E804:  LDY $20         ; Delay expired?
         BNE C3E812      ; Exit if not
         INC $26         ; Next: C3/E813
         JSR C3E1DF      ; Queue fade-in
         LDY #$00F0      ; Switch delay
         STY $20         ; Set for names
C3E812:  RTS

; 89: Switch Umaro's names
C3E813:  LDY $20         ; Delay expired?
         BNE C3E821      ; Exit if not
         INC $26         ; Next: C3/E822
         JSR C3E206      ; Switch names
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3E821:  RTS

; 8A: Fade all but Umaro's name
C3E822:  LDY $20         ; Delay expired?
         BNE C3E838      ; Exit if not
         LDA #$38        ; C3/E2E7
         STA $26         ; Next: Fd name
         LDY #$0078      ; Fade delay
         STY $20         ; Set for name
         JSR C3E145      ; Fade BGs
         JSR C3E29E      ; Fade sprites
         JSR C3E845      ; Scroll table
C3E838:  RTS

; Set to scroll BG1 westward for 20 seconds
C3E839:  LDY #$04B0      ; Frames: 1200
         JMP C3DFED      ; Queue panning

; Set to scroll BG1 westward for 5.2 seconds
C3E83F:  LDY #$0138      ; Frames: 312
         JMP C3DFED      ; Queue panning

; Set to scroll BG1 westward for 3 seconds
C3E845:  LDY #$00B4      ; Frames: 180
         JMP C3DFED      ; Queue panning

; Queue mosaic effect for book
C3E84B:  TDC             ; Min slot: 0
         LDY #C3E852     ; C3/E852
         JMP C31173      ; Queue anim fn

; Handle mosaic effect for book
C3E852:  TAX             ; Index mode
         JMP (C3E856,X)  ; Handle mode

; Jump table for the above
C3E856:  dw C3E85A       ; Initialize mosaic
         dw C3E865       ; Sustain mosaic

; Mode 0: Initialize mosaic
C3E85A:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         STZ $33CA,X     ; Intensity: 0
         STZ $3349,X     ; Wait timer: 0

; Mode 1: Sustain mosaic
C3E865:  LDX $2D         ; Queue index
         LDA $3349,X     ; Delay expired?
         BEQ C3E871      ; Proceed if so
         DEC $3349,X     ; Delay -1
         SEC             ; Set to requeue
         RTS             ; Exit
C3E871:  LDA $33CA,X     ; Intensity
         ORA #$0F        ; Layers: All
         STA $B5         ; Set mosaic
         LDX $2D         ; ...
         LDA $33CA,X     ; Intensity
         CLC             ; Prepare ADC
         ADC #$10        ; Intensity +1
         STA $33CA,X     ; Save changes
         LDA #$10        ; Frames: 16
         STA $3349,X     ; Set next wait
         SEC             ; Set to requeue
         RTS

; Scroll BG1 westward (unused)
C3E88A:  LDA $23         ; NMI count
         AND #$03        ; Now 0-3
         BNE C3E896      ; Exit if > 0
         REP #$20        ; 16-bit A
         INC $35         ; BG1 X-Pos +1
         SEP #$20        ; 8-bit A
C3E896:  RTS

; Create "as"
C3E897:  LDA #$03        ; Min slot: 24
         LDY #C3DE84     ; C3/DE84
         JSR C31173      ; Queue anim fn
         REP #$20        ; 16-bit A
         LDA #$8E38      ; Anim table ptr
         STA $7E32C9,X   ; Set sprite's
         LDA #$0258      ; Frames: 600
         STA $7E3349,X   ; Set hide delay
         SEP #$20        ; 8-bit A
         LDA #$C2        ; Bank: C2
         STA $7E35CA,X   ; Set ptr HB
         LDA #$79        ; X: 121
         STA $7E33CA,X   ; Set sprite's
         LDA #$C0        ; Y: 192
         STA $7E344A,X   ; Set sprite's
         RTS

; Create Umaro's skull
C3E8C4:  JSR C3E9D2      ; Queue anim fn
         REP #$20        ; 16-bit A
         LDA #$F56E      ; Anim table ptr
         STA $7E32C9,X   ; Set sprite's
         SEP #$20        ; 8-bit A
         LDA #$CF        ; Bank: CF
         STA $7E35CA,X   ; Set ptr HB
         LDA #$C4        ; X: 196
         STA $7E33CA,X   ; Set sprite's
         LDA #$4F        ; Y: 79
         JMP C3EA68      ; Set Y, pan flag

; Create four playing cards
C3E8E3:  JSR C3E97A      ; Queue card 1
         LDA #$78        ; X: 120
         STA $7E33CA,X   ; Set card 1's
         LDA #$50        ; X: 80
         STA $7E33CA,X   ; Should be Y...
         REP #$20        ; 16-bit A
         LDA #$0080      ; V-Spd: +0.5 px
         STA $7E3549,X   ; Set card 1's
         LDA #$0020      ; H-Spd: +0.125 px
         STA $7E34C9,X   ; Set card 1's
         SEP #$20        ; 8-bit A
         JSR C3E97A      ; Queue card 2
         LDA #$04        ; Pose timer: 4
         STA $7E36CA,X   ; Overwritten...
         LDA #$48        ; X: 72
         STA $7E33CA,X   ; Set card 2's
         LDA #$C0        ; Y: 192
         STA $7E344A,X   ; Set card 2's
         REP #$20        ; 16-bit A
         LDA #$0060      ; V-Spd: +0.375 px
         STA $7E3549,X   ; Set card 2's
         LDA #$0040      ; H-Spd: +0.25 px
         STA $7E34C9,X   ; Set card 2's
         SEP #$20        ; 8-bit A
         JSR C3E97A      ; Queue card 3
         LDA #$0C        ; Pose timer: 12
         STA $7E36CA,X   ; Overwritten...
         LDA #$98        ; X: 152
         STA $7E33CA,X   ; Set card 3's
         LDA #$10        ; Y: 16
         STA $7E344A,X   ; Set card 3's
         REP #$20        ; 16-bit A
         LDA #$0080      ; V-Spd: +0.5 px
         STA $7E3549,X   ; Set card 3's
         LDA #$FFE0      ; H-Spd: -0.125 px
         STA $7E34C9,X   ; Set card 3's
         SEP #$20        ; 8-bit A
         JSR C3E97A      ; Queue card 4
         LDA #$12        ; Pose timer: 18
         STA $7E36CA,X   ; Overwritten...
         LDA #$D0        ; X: 208
         STA $7E33CA,X   ; Set card 4's
         LDA #$80        ; Y: 128
         STA $7E344A,X   ; Set card 4's
         REP #$20        ; 16-bit A
         LDA #$0080      ; V-Spd: +0.5 px
         STA $7E3549,X   ; Set card 4's
         LDA #$00A0      ; H-Spd: +0.625 px
         STA $7E34C9,X   ; Set card 4's
         SEP #$20        ; 8-bit A
         RTS

; Queue current playing card
C3E97A:  LDA #$00        ; Min slot: 0
         LDY #C3DEAB     ; C3/DEAB
         JSR C31173      ; Queue anim fn
         REP #$20        ; 16-bit A
         LDA #$92FA      ; Anim table ptr
         STA $7E32C9,X   ; Set sprite's
         SEP #$20        ; 8-bit A
         LDA #$C2        ; Bank: C2
         STA $7E35CA,X   ; Set ptr HB
         RTS

; Create face in Gau's diving helmet
C3E994:  JSR C3E9D2      ; Queue anim fn
         REP #$20        ; 16-bit A
         LDA #$F647      ; Anim table ptr
         STA $7E32C9,X   ; Set sprite's
         SEP #$20        ; 8-bit A
         LDA #$CF        ; Bank: CF
         STA $7E35CA,X   ; Set ptr HB
         LDA #$CB        ; X: 203
         STA $7E33CA,X   ; Set sprite's
         LDA #$5F        ; Y: 95
         JMP C3EA68      ; Set Y, pan flag

; Create Shadow's apple
C3E9B3:  JSR C3E9D2      ; Queue anim fn
         REP #$20        ; 16-bit A
         LDA #$9497      ; Anim table ptr
         STA $7E32C9,X   ; Set sprite's
         SEP #$20        ; 8-bit A
         LDA #$C2        ; Bank: C2
         STA $7E35CA,X   ; Set ptr HB
         LDA #$C0        ; X: 192
         STA $7E33CA,X   ; Set sprite's
         LDA #$57        ; Y: 87
         JMP C3EA68      ; Set Y, pan flag

; Queue regular permanent sprite
C3E9D2:  LDA #$03        ; Min slot: 24
         LDY #C3DEAB     ; C3/DEAB
         JSR C31173      ; Queue OAM fn
         RTS

; Queue regular permanent sprite (unused variant)
C3E9DB:  LDA #$02        ; Min slot: 16
         LDY #C3DEAB     ; C3/DEAB
         JSR C31173      ; Queue OAM fn
         RTS

; Create glowing eye in Gogo's helmet
C3E9E4:  JSR C3E9D2      ; Queue anim fn
         REP #$20        ; 16-bit A
         LDA #$F450      ; Anim table ptr
         STA $7E32C9,X   ; Set sprite's
         SEP #$20        ; 8-bit A
         LDA #$CF        ; Bank: CF
         STA $7E35CA,X   ; Set ptr HB
         LDA #$C8        ; X: 200
         STA $7E33CA,X   ; Set sprite's
         LDA #$61        ; Y: 97
         JMP C3EA68      ; Set Y, pan flag

; Create glint on Terra's pendant
C3EA03:  JSR C3E9D2      ; Queue anim fn
         REP #$20        ; 16-bit A
         LDA #$F5B4      ; Anim table ptr
         STA $7E32C9,X   ; Set sprite's
         SEP #$20        ; 8-bit A
         LDA #$CF        ; Bank: CF
         STA $7E35CA,X   ; Set ptr HB
         LDA #$80        ; X: 128
         STA $7E33CA,X   ; Set sprite's
         LDA #$60        ; Y: 96
         STA $7E344A,X   ; Set sprite's
         RTS

; Create Mog's mini moogles and winding key
C3EA24:  JSR C3E9D2      ; Queue key anim
         REP #$20        ; 16-bit A
         LDA #$F515      ; Anim table ptr
         STA $7E32C9,X   ; Set key's
         SEP #$20        ; 8-bit A
         LDA #$CF        ; Bank: CF
         STA $7E35CA,X   ; Set ptr HB
         LDA #$E0        ; X: 224
         STA $7E33CA,X   ; Set key's
         LDA #$6F        ; Y: 111
         JSR C3EA68      ; Set Y, pan flag
         JSR C3EA73      ; Queue moogle 1
         LDA #$BA        ; X: 186
         STA $7E33CA,X   ; Set moogle 1's
         JSR C3EA73      ; Queue moogle 2
         LDA #$C6        ; X: 198
         STA $7E33CA,X   ; Set moogle 2's
         JSR C3EA73      ; Queue moogle 3
         LDA #$D1        ; X: 209
         STA $7E33CA,X   ; Set moogle 3's
         JSR C3EA73      ; Queue moogle 4
         LDA #$DC        ; X: 220
         STA $7E33CA,X   ; Set moogle 4's
         RTS

; Set sprite to pan with BG1, define Y position
C3EA68:  STA $7E344A,X   ; Set Y position
C3EA6C:  LDA #$01        ; Pans with BG1
         STA $7E364A,X   ; Set sprite flags
         RTS

; Queue current mini moogle
C3EA73:  LDA #$02        ; Min slot: 16
         LDY #C3EAFC     ; C3/EAFC
         JSR C31173      ; Queue anim fn
         RTS

; Create Umaro's moogles
C3EA7C:  JSR C3EA73      ; Queue moogle 1
         JSR C3EAF5      ; Anim mode: 5
         LDA #$3A        ; Base X: 58
         STA $7E33CA,X   ; Set moogle 1's
         REP #$20        ; 16-bit A
         LDA #$01A4      ; Frames: 420
         STA $7E3349,X   ; Set walk timer
         LDA #$F47F      ; Bump anim ptr
         STA $7E37C9,X   ; Set moogle 1's
         SEP #$20        ; 8-bit A
         JSR C3EA73      ; Queue moogle 2
         JSR C3EAF5      ; Anim mode: 5
         LDA #$2E        ; Base X: 46
         STA $7E33CA,X   ; Set moogle2's
         REP #$20        ; 16-bit A
         LDA #$01B8      ; Frames: 440
         STA $7E3349,X   ; Set walk timer
         LDA #$F485      ; Bump anim ptr
         STA $7E37C9,X   ; Set moogle2's
         SEP #$20        ; 8-bit A
         JSR C3EA73      ; Queue moogle 3
         JSR C3EAF5      ; Anim mode: 5
         LDA #$21        ; Base X: 33
         STA $7E33CA,X   ; Set moogle 3's
         REP #$20        ; 16-bit A
         LDA #$01CC      ; Frames: 460
         STA $7E3349,X   ; Set walk timer
         LDA #$F48B      ; Bump anim ptr
         STA $7E37C9,X   ; Set moogle 3's
         SEP #$20        ; 8-bit A
         JSR C3EA73      ; Queue moogle 4
         JSR C3EAF5      ; Anim mode: 5
         LDA #$14        ; Base X: 20
         STA $7E33CA,X   ; Set moogle 3's
         REP #$20        ; 16-bit A
         LDA #$01E0      ; Frames: 480
         STA $7E3349,X   ; Set walk timer
         LDA #$F491      ; Bump anim ptr
         STA $7E37C9,X   ; Set moogle 4's
         SEP #$20        ; 8-bit A
         RTS

; Initialize moogle's animation mode for Umaro
C3EAF5:  LDA #$05        ; Approach bones
         STA $7E3649,X   ; Set anim mode
         RTS

; Animate mini moogle
C3EAFC:  TAX             ; Index mode
         JMP (C3EB00,X)  ; Handle mode

; Jump table
C3EB00:  dw C3EB10       ; Initialize data
         dw C3EB35       ; Spin around
         dw C3EB5E       ; Face left
         dw C3EB7B       ; Jump down
         dw C3EB97       ; Walk away from tree
         dw C3EB9C       ; Initialize data
         dw C3EBA9       ; Walk toward bones
         dw C3EBD0       ; Stop and fall down

; Mode 0: Initialize data
C3EB10:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         REP #$20        ; 16-bit A
         LDA #$F458      ; Anim table ptr
         STA $32C9,X     ; Set sprite's
         LDA #$0168      ; Frames: 360
         STA $3349,X     ; Set spin timer
         SEP #$20        ; 8-bit A
         LDA #$64        ; Y: 100
         STA $344A,X     ; Set sprite's
         LDA #$CF        ; Bank: CF
         STA $35CA,X     ; Set ptr HB
         JSR C3EA6C      ; Follow BG1: Y
         JSR C31206      ; Set pose timer

; Mode 1: Spin around
C3EB35:  LDX $2D         ; Queue index
         LDY $3349,X     ; Mode expired?
         BNE C3EB56      ; Branch if not
         INC $3649,X     ; Mode +1
         REP #$20        ; 16-bit A
         LDA #$F47C      ; Anim table ptr
         STA $32C9,X     ; Set sprite's
         SEP #$20        ; 8-bit A
         LDA #$CF        ; Bank: CF
         STA $35CA,X     ; Set ptr HB
         LDA #$10        ; Frames: 16
         STA $3349,X     ; Set jump timer
         JSR C31206      ; Set pose timer
C3EB56:  JSR C3CFE5      ; Mode timer -1
         JSR C3DEC0      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS

; Mode 2: Jump down
C3EB5E:  LDX $2D         ; Queue index
         LDY $3349,X     ; Mode expired?
         BNE C3EB6D      ; Branch if not
         INC $3649,X     ; Mode +1
         LDA #$3C        ; Frames: 60
         STA $3349,X     ; Set walk delay
C3EB6D:  JSR C3CFE5      ; Mode timer -1
         JSR C3EBF0      ; Adjust Y-Pos
         JSR C3DEC0      ; Scroll & OAM
         INC $35C9,X     ; Y-Pos mod +1
         SEC             ; Set to requeue
         RTS

; Mode 3: Face left
C3EB7B:  LDX $2D         ; Queue index
         LDY $3349,X     ; Mode expired?
         BNE C3EB8F      ; Branch if not
         JSR C3EBD5      ; Set to walk
         REP #$20        ; 16-bit A
         LDA #$012C      ; Frames: 300
         STA $3349,X     ; No use...
         SEP #$20        ; 8-bit A
C3EB8F:  JSR C3CFE5      ; Mode timer -1
         JSR C3DEC0      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS

; Mode 4: Walk away from tree
C3EB97:  JSR C3DEC0      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS

; Mode 5: Initialize data
C3EB9C:  LDX $2D         ; Queue index
         JSR C3EBD5      ; Set to walk
         LDA #$70        ; Y: 112
         STA $344A,X     ; Set sprite's
         JSR C3EA6C      ; Follow BG1: Y

; Mode 6: Walk toward bones
C3EBA9:  LDX $2D         ; Queue index
         LDY $3349,X     ; Mode expired?
         BNE C3EBC8      ; Branch if not
         INC $3649,X     ; Mode +1
         REP #$20        ; 16-bit A
         STZ $34C9,X     ; H-Speed: 0
         LDA $37C9,X     ; Queue anim ptr
         STA $32C9,X     ; Set as current
         SEP #$20        ; 8-bit A
         LDA #$CF        ; Bank: CF
         STA $35CA,X     ; Set ptr HB
         JSR C31206      ; Set pose timer
C3EBC8:  JSR C3CFE5      ; Mode timer -1
         JSR C3DEC0      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS

; Mode 7: Stop and fall down
C3EBD0:  JSR C3DEC0      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS

; Set mini moogle to walk eastward
C3EBD5:  INC $3649,X     ; Mode +1
         REP #$20        ; 16-bit A
         LDA #$F473      ; Anim table ptr
         STA $32C9,X     ; Set sprite's
         LDA #$0040      ; H-Spd: +0.25 px
         STA $34C9,X     ; Set sprite's
         SEP #$20        ; 8-bit A
         LDA #$CF        ; Bank: CF
         STA $35CA,X     ; Set ptr HB
         JMP C31206      ; Set pose timer

; Adjust jumping mini moogle's Y position
C3EBF0:  LDX $2D         ; Queue index
         LDA $35C9,X     ; Modifier index
         AND #$0F        ; ...
         TAX             ; Index it
         LDA $CFF55E,X   ; Y modifier
         STA $E0         ; Memorize it
         BMI C3EC0D      ; Branch if up
         LDX $2D         ; Queue index
         LDA $344A,X     ; Sprite's Y
         CLC             ; Prepare ADC
         ADC $E0         ; Add modifier
         STA $344A,X     ; Save changes
         BRA C3EC23      ; Exit

; Fork: Shift upward
C3EC0D:  LDX $2D         ; Queue index
         LDA $00E0       ; Y modifier
         BPL C3EC17      ; ...
         EOR #$FF        ; Invert it
         INC A           ; Add 1
C3EC17:  STA $00E0       ; Save changes
         LDA $344A,X     ; Sprite's Y
         SEC             ; Prepare SBC
         SBC $E0         ; Sub modifier
         STA $344A,X     ; Save changes
C3EC23:  RTS

; Queue double-headed coin
C3EC24:  LDA #$02        ; Min slot: 16
         LDY #C3ED39     ; C3/ED39
         JSR C31173      ; Queue anim fn
         RTS

; Set to create glints on brush
C3EC2D:  LDA #$00        ; Min slot: 0
         LDY #C3EC48     ; C3/EC48
         JSR C31173      ; Queue anim fn
         RTS

; Set to create glints on katana
C3EC36:  LDA #$00        ; Min slot: 0
         LDY #C3ECAE     ; C3/ECAE
         JSR C31173      ; Queue anim fn
         RTS

; Queue brush or katana glint
C3EC3F:  LDA #$02        ; Min slot: 16
         LDY #C3ED14     ; C3/ED14
         JSR C31173      ; Queue anim fn
         RTS

; Create a series of glints on Relm's brush
C3EC48:  TAX             ; Index mode
         JMP (C3EC4C,X)  ; Handle mode

; Jump table for the above
C3EC4C:  dw C3EC50       ; Initialize wave
         dw C3EC67       ; Create wave

; Mode 0: Initialize wave
C3EC50:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         REP #$20        ; 16-bit A
         LDA #$0168      ; Frames: 360
         STA $3349,X     ; Set wave delay
         SEP #$20        ; 8-bit A
         LDA #$E4        ; X: 228
         STA $C7         ; Set base X
         LDA #$03        ; Glints: 3
         STA $C9         ; Set counter

; Mode 1: Create wave
C3EC67:  LDA $C9         ; Glints left
         BEQ C3ECAC      ; Dequeue if 0
         LDX $2D         ; Queue index
         LDY $3349,X     ; Delay expired?
         BNE C3ECA7      ; Branch if not
         LDA #$08        ; Frames: 8
         STA $3349,X     ; Set next delay
         PHB             ; Save DB
         LDA #$00        ; ...
         PHA             ; ...
         PLB             ; ...
         JSR C3EC3F      ; Queue glint
         LDA #$68        ; Y: 104
         STA $7E344A,X   ; Set glint's
         REP #$20        ; 16-bit A
         LDA #$F5B4      ; Anim table ptr
         STA $7E32C9,X   ; Set glint's
         SEP #$20        ; 8-bit A
         LDA #$CF        ; Bank: CF
         STA $7E35CA,X   ; Set ptr HB
         LDA $C7         ; Base X
         STA $7E33CA,X   ; Set glint's
         PLB             ; Restore DB
         DEC $C7         ; Base X -1
         DEC $C7         ; Base X -1
         DEC $C7         ; Base X -1
         DEC $C7         ; Base X -1
         DEC $C9         ; Glints left -1
C3ECA7:  JSR C3CFE5      ; Delay -1
         SEC             ; Set to requeue
         RTS             ; Exit
C3ECAC:  CLC             ; Set to dequeue
         RTS

; Create a series of glints on Cyan's katana
C3ECAE:  TAX             ; Index mode
         JMP (C3ECB2,X)  ; Handle mode

; Jump table for the above
C3ECB2:  dw C3ECB6       ; Initialize wave
         dw C3ECCD       ; Create wave

; Mode 0: Initialize wave
C3ECB6:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         REP #$20        ; 16-bit A
         LDA #$0168      ; Frames: 360
         STA $3349,X     ; Set wave delay
         SEP #$20        ; 8-bit A
         LDA #$C8        ; X: 200
         STA $C7         ; Set base X
         LDA #$04        ; Glints: 4
         STA $C9         ; Set counter

; Mode 1: Create wave
C3ECCD:  LDA $C9         ; Glints left
         BEQ C3ED12      ; Dequeue if 0
         LDX $2D         ; Queue index
         LDY $3349,X     ; Delay expired?
         BNE C3ED0D      ; Branch if not
         LDA #$08        ; Frames: 8
         STA $3349,X     ; Set next delay
         PHB             ; Save DB
         LDA #$00        ; ...
         PHA             ; ...
         PLB             ; ...
         JSR C3EC3F      ; Queue glint
         LDA #$60        ; Y: 96
         STA $7E344A,X   ; Set glint's
         REP #$20        ; 16-bit A
         LDA #$F5FA      ; Anim table ptr
         STA $7E32C9,X   ; Set glint's
         SEP #$20        ; 8-bit A
         LDA #$CF        ; Bank: CF
         STA $7E35CA,X   ; Set ptr HB
         LDA $C7         ; Base X
         STA $7E33CA,X   ; Set glint's
         PLB             ; Restore DB
         DEC $C7         ; Base X -1
         DEC $C7         ; Base X -1
         DEC $C7         ; Base X -1
         DEC $C7         ; Base X -1
         DEC $C9         ; Glints left -1
C3ED0D:  JSR C3CFE5      ; Delay -1
         SEC             ; Set to requeue
         RTS             ; Exit
C3ED12:  CLC             ; Set to dequeue
         RTS

; Animate glint on brush or katana
C3ED14:  TAX             ; Index mode
         JMP (C3ED18,X)  ; Handle mode

; Jump table for the above
C3ED18:  dw C3ED1C       ; Initialize sprite
         dw C3ED29       ; Sustain sprite

; Mode 0: Initialize sprite
C3ED1C:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         LDA #$01        ; Pans with BG1
         STA $364A,X     ; Set OBJ flags
         JSR C31206      ; Set pose timer

; Mode 1: Sustain sprite
C3ED29:  LDX $2D         ; Queue index
         LDA $36CA,X     ; Pose timer
         CMP #$FE        ; Set as endless?
         BEQ C3ED37      ; Delete if so
         JSR C3DEC0      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS             ; Exit
C3ED37:  CLC             ; Set to dequeue
         RTS

; Animate double-headed coin
C3ED39:  TAX             ; Index mode
         JMP (C3ED3D,X)  ; Handle mode

; Jump table for the above
C3ED3D:  dw C3ED41       ; Initialize sprite
         dw C3ED6D       ; Sustain sprite

; Mode 0: Initialize sprite
C3ED41:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         REP #$20        ; 16-bit A
         LDA #$EC93      ; Anim table ptr
         STA $32C9,X     ; Set sprite's
         LDA #$0080      ; H-Spd: +0.5 px
         STA $34C9,X     ; Set sprite's
         SEP #$20        ; 8-bit A
         LDA #$C8        ; Frames: 200
         STA $3349,X     ; Set roll timer
         LDA #$D8        ; Bank: D8
         STA $35CA,X     ; Set ptr HB
         LDA #$10        ; X: 16
         STA $33CA,X     ; Set sprite's
         LDA #$64        ; Y: 100
         STA $344A,X     ; Set sprite's
         JSR C31206      ; Set pose timer

; Mode 1: Sustain sprite
C3ED6D:  LDX $2D         ; Queue index
         LDA $3349,X     ; Stop rolling?
         BNE C3ED77      ; Branch if not
         STZ $34C9,X     ; H-Speed: 0
C3ED77:  DEC $3349,X     ; Roll timer -1
         JSR C3DEC0      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS

; Set to animate Strago's book
C3ED7F:  JSR C3EDBE      ; Queue anim fn
         REP #$20        ; 16-bit A
         LDA #$8B72      ; Anim table ptr
         STA $7E32C9,X   ; Set book's
         SEP #$20        ; 8-bit A
         LDA #$C2        ; Bank: C2
         STA $7E35CA,X   ; Set ptr HB
         RTS

; Set to animate first book
C3ED94:  JSR C3EDBE      ; Queue anim fn
         REP #$20        ; 16-bit A
         LDA #$8B63      ; Anim table ptr
         STA $7E32C9,X   ; Set book's
         SEP #$20        ; 8-bit A
         LDA #$C2        ; Bank: C2
         STA $7E35CA,X   ; Set ptr HB
         RTS

; Set to animate last book
C3EDA9:  JSR C3EDBE      ; Queue anim fn
         REP #$20        ; 16-bit A
         LDA #$8B45      ; Anim table ptr
         STA $7E32C9,X   ; Set book's
         SEP #$20        ; 8-bit A
         LDA #$C2        ; Bank: C2
         STA $7E35CA,X   ; Set ptr HB
         RTS

; Set to animate book
C3EDBE:  TDC             ; Clear A
         TAY             ; Clear Y
         STA $99         ; Last page: N
         STY $60         ; Always 0...
         LDA #$01        ; Min slot: 8
         LDY #C3EE04     ; C3/EE04
         JSR C31173      ; Queue anim fn
         RTS

; Integrate decompressed tilemap segment, adjust attributes
C3EDCD:  STX $E7         ; Set src LBs
         LDA #$7F        ; Bank: 7F
         STA $E9         ; Set src HB
         STY $EB         ; Set dst LBs
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set dst HB
         LDX $00         ; Rows done: 0
         REP #$20        ; 16-bit A
C3EDDD:  TDC             ; Clear A
         TAY             ; Index: 0
C3EDDF:  LDA [$E7],Y     ; Attributes
         CLC             ; Prepare ADC
         ADC $60         ; Always 0...
         STA [$EB],Y     ; Put in map
         INY             ; Index +1
         INY             ; Index +1
         CPY $E0         ; End of row?
         BNE C3EDDF      ; Loop if not
         LDA $E7         ; Source LBs
         CLC             ; Prepare ADC
         ADC #$0040      ; Go 1 row down
         STA $E7         ; Save changes
         LDA $EB         ; Dest LBs
         CLC             ; Prepare ADC
         ADC #$0040      ; Go 1 row down
         STA $EB         ; Save changes
         INX             ; Rows done +1
         CPX $E2         ; More left?
         BNE C3EDDD      ; Loop if so
         SEP #$20        ; 8-bit A
         RTS

; Animate book
C3EE04:  TAX             ; Index mode
         JMP (C3EE08,X)  ; Handle mode

; Jump table for the above
C3EE08:  dw C3EE0E       ; Initialize timer
         dw C3EE18       ; Check if last page
         dw C3EE1C       ; Update tilemap

; Mode 0: Initialize timer
C3EE0E:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         JSR C31206      ; Set pose timer
         SEC             ; Set to requeue
         RTS

; Mode 1: Check if last page
C3EE18:  LDA $99         ; Last page?
         BNE C3EE59      ; Branch if so

; Mode 2: Update tilemap
C3EE1C:  LDX $2D         ; Queue index
         JSR C31227      ; Pose timer -1
         LDX $2D         ; Queue index
         SEP #$10        ; 8-bit X, Y
         LDA $36C9,X     ; Pose index
         TAY             ; Index it
         REP #$20        ; 16-bit A
         LDA [$EB],Y     ; Pose info loc
         STA $E7         ; Set src LBs
         INY             ; ...
         INY             ; ...
         SEP #$20        ; 8-bit A
         LDA $35CA,X     ; Anim ptr HB
         STA $E9         ; Set src HB
         REP #$10        ; 16-bit X, Y
         LDY $00         ; Src index: 0
         REP #$20        ; 16-bit A
         LDA [$E7],Y     ; Column count
         STA $E0         ; Set width
         INY             ; Src index +1
         INY             ; Src index +1
         LDA [$E7],Y     ; Row count
         STA $E2         ; Set height
         INY             ; Src index +1
         INY             ; Src index +1
         LDA [$E7],Y     ; Source LBs
         TAX             ; Put in X
         INY             ; Src index +1
         INY             ; Src index +1
         LDA [$E7],Y     ; Dest LBs
         TAY             ; Put in Y
         SEP #$20        ; 8-bit A
         JSR C3EDCD      ; Replace tiles
         SEC             ; Set to requeue
         RTS

; Fork: Set to stop animation
C3EE59:  STZ $99         ; ...
         LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         REP #$20        ; 16-bit A
         LDA #$8B54      ; Anim table ptr
         STA $32C9,X     ; Set book's
         SEP #$20        ; 8-bit A
         LDA #$C2        ; Bank: C2
         STA $35CA,X     ; Set ptr HB
         JSR C31206      ; Set pose timer
         BRA C3EE1C      ; Replace tiles

; Unpack and upload large font graphics for actor scene
C3EE74:  LDY #$BA00      ; Source LBs
         LDA #$C4        ; Source HB
         JSR C3DD61      ; Unpack GFX
         LDY #$C000      ; 7E/C000
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         LDY #$0900      ; Bytes: 2304
         STY $EB         ; Set data size
         LDY #$7000      ; VRAM pointer
         JMP C3DD86      ; Upload GFX

; Unpack and upload BG graphics and tilemaps for actor scene
C3EE90:  LDY #$C008      ; Source LBs
         LDA #$C4        ; Source HB
         JSR C3DD61      ; Unpack data

; Fork: Copy table's map to BG1 tilemap A
C3EE98:  LDY #$3849      ; BG1 map A
         STY $EB         ; Set dst LBs
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set dst HB
         JSR C3EF10      ; Move data

; Fork: Copy table's map to BG1 tilemap B
C3EEA4:  LDY #$4049      ; BG1 map B
         STY $EB         ; Set dst LBs
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set dst HB
         JSR C3EF10      ; Move data

; Fork: Upload tall items and table side graphics
C3EEB0:  LDY #$C000      ; 7E/C000
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         LDY #$1F60      ; Bytes: 8032
         STY $EB         ; Set data size
         STZ $ED         ; Attrib LB: 0
         STZ $EE         ; Attrib HB: 0
         LDY #$3000      ; VRAM pointer
         JSR C3DDB9      ; Upload data

; Fork: Upload large items, tabletop, and overlay graphics
C3EEC8:  LDY #$DF60      ; 7E/DF60
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         LDY #$0B40      ; Bytes: 2880
         STY $EB         ; Set data size
         STZ $ED         ; Attrib LB: 0
         STZ $EE         ; Attrib HB: 0
         LDY #$4000      ; VRAM pointer
         JSR C3DDB9      ; Upload data

; Fork: Upload book graphics
C3EEE0:  LDY #$EAA0      ; 7E/EAA0
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         LDY #$0E00      ; Bytes: 3584
         STY $EB         ; Set data size
         STZ $ED         ; Attrib LB: 0
         STZ $EE         ; Attrib HB: 0
         LDY #$5000      ; VRAM pointer
         JSR C3DDB9      ; Upload data

; Fork: Upload transparent overlay tilemap (BG2)
C3EEF8:  LDY #$0448      ; 7F/0448
         STY $E7         ; Set src LBs
         LDA #$7F        ; Bank: 7F
         STA $E9         ; Set src HB
         LDY #$0780      ; Bytes: 1920
         STY $EB         ; Set data size
         STZ $ED         ; Attrib LB: 0
         STZ $EE         ; Attrib HB: 0
         LDY #$1000      ; VRAM pointer
         JMP C3DDB9      ; Upload data

; Relocate decompressed tilemap for table
C3EF10:  LDY #$F8A0      ; 7E/F8A0
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         LDY #$0780      ; Bytes: 1920
         STY $EF         ; Set data size
         JMP C3D6EE      ; Move data

; Set to upload BG1 and BG3 tilemaps for actor scene
C3EF21:  LDY #$1800      ; $3000
         STY $1B         ; Set VRAM ptr
         LDY #$7849      ; 7E/7849
         STY $1D         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $1F         ; Set src HB
         LDY #$0800      ; Bytes: 2048
         STY $19         ; Set data size
         LDY #$0000      ; $0000
         STY $14         ; Set VRAM ptr
         LDY #$3849      ; 7E/3849
         STY $16         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $18         ; Set src HB
         LDY #$1000      ; Bytes: 4096
         STY $12         ; Set data size
         RTS

; Unpack and upload apple and shuriken graphics
C3EF48:  LDY #$F477      ; Source LBs
         LDA #$C4        ; Source HB
         JSR C3DD61      ; Unpack GFX
         LDY #$C000      ; 7E/C000
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         LDY #$0380      ; Bytes: 896
         STY $EB         ; Set data size
         STZ $ED         ; Attrib LB: 0
         STZ $EE         ; Attrib HB: 0
         LDY #$6000      ; VRAM pointer
         JMP C3DDB9      ; Upload GFX

; Draw Cyan's katana; unpack and upload glint
C3EF68:  JSR C3F036      ; Handle glint
         LDY #$0026      ; Tiles: 19
         STY $E0         ; Set width
         LDY #$0002      ; Tiles: 2
         STY $E2         ; Set height
         LDX #$03E0      ; Src: 7F/03E0
         LDY #$3BA1      ; Dst: 7E/3BA1
         JMP C3EDCD      ; Draw katana

; Unpack and upload coin graphics
C3EF7E:  JSR C3EF87      ; Unpack data
         LDY #$6000      ; VRAM pointer
         JMP C3DDB9      ; Upload data

; Unpack skull and coin graphics; prepare upload
C3EF87:  LDY #$9D4B      ; Source LBs
         LDA #$D9        ; Source HB
         JSR C3DD61      ; Unpack GFX
         LDY #$C000      ; 7E/C000
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         LDY #$0800      ; Bytes: 896
         STY $EB         ; Set data size
         STZ $ED         ; Attrib LB: 0
         STZ $EE         ; Attrib HB: 0
         RTS

; Draw Mog's tree; unpack and upload sprites
C3EFA2:  JSR C3F036      ; Do sprites
         LDY #$000E      ; Tiles: 7
         STY $E0         ; Set width
         LDY #$0008      ; Tiles: 8
         STY $E2         ; Set height
         LDX #$0020      ; Src: 7F/0020
         LDY #$3A77      ; Dst: 7E/3A77
         JMP C3EDCD      ; Draw tree

; Draw Gogo's helmet; unpack and upload glint
C3EFB8:  JSR C3F036      ; Handle glint
         LDY #$001C      ; Tiles: 14
         STY $E0         ; Set width
         LDY #$0009      ; Tiles: 9
         STY $E2         ; Set height
         LDX #$002E      ; Src: 7F/002E
         LDY #$3A2D      ; Dst: 7E/3A2D
         JMP C3EDCD      ; Draw helmet

; Draw Gau's diving helmet; unpack and upload face
C3EFCE:  JSR C3F056      ; Handle face
         LDY #$000C      ; Tiles: 6
         STY $E0         ; Set width
         LDY #$0007      ; Tiles: 7
         STY $E2         ; Set height
         LDX #$004A      ; Src: 7F/004A
         LDY #$3AB7      ; Dst: 7E/3AB7
         JMP C3EDCD      ; Draw helmet

; Draw Terra's cocktail glasses; unpack and upload glint
C3EFE4:  JSR C3F036      ; Handle glint
         LDY #$000E      ; Tiles: 7
         STY $E0         ; Set width
         LDY #$0005      ; Tiles: 5
         STY $E2         ; Set height
         LDX #$0220      ; Src: 7F/0220
         LDY #$3B35      ; Dst: 7E/3B35
         JMP C3EDCD      ; Draw glasses

; Draw Locke and Celes's bouquet
C3EFFA:  LDY #$0018      ; Tiles: 12
         STY $E0         ; Set width
         LDY #$0006      ; Tiles: 6
         STY $E2         ; Set height
         LDX #$0274      ; Src: 7F/0274
         LDY #$3B69      ; Dst: 7E/3B69
         JMP C3EDCD      ; Replace tiles

; Draw Relm's brush; unpack and upload glint
C3F00D:  JSR C3F036      ; Handle glint
         LDY #$0014      ; Tiles: 10
         STY $E0         ; Set width
         LDY #$0002      ; Tiles: 2
         STY $E2         ; Set height
         LDX #$0360      ; Src: 7F/0360
         LDY #$3BF3      ; Dst: 7E/3BF3
         JMP C3EDCD      ; Draw brush

; Draw an open book
C3F023:  LDY #$001C      ; Tiles: 14
         STY $E0         ; Set width
         LDY #$0006      ; Tiles: 6
         STY $E2         ; Set height
         LDX #$0BC8      ; Src: 7F/0BC8
         LDY #$3AD9      ; Dst: 7E/3AD9
         JMP C3EDCD      ; Replace tiles

; Unpack and upload card, glint, moogle, and winding key graphics
C3F036:  LDY #$F6FB      ; Source LBs
         LDA #$C4        ; Source HB
         JSR C3DD61      ; Unpack GFX
         LDY #$C000      ; 7E/C000
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         LDY #$0DF0      ; Bytes: 3568
         STY $EB         ; Set data size
         STZ $ED         ; Attrib LB: 0
         STZ $EE         ; Attrib HB: 0
         LDY #$6000      ; VRAM pointer
         JMP C3DDB9      ; Upload GFX

; Unpack and upload face graphics for Gau's scene
C3F056:  LDY #$A4E5      ; Source LBs
         LDA #$D9        ; Source HB
         JSR C3DD61      ; Unpack GFX
         LDY #$C000      ; 7E/C000
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         LDY #$00C0      ; Bytes: 192
         STY $EB         ; Set data size
         LDY #$6000      ; VRAM pointer
         JMP C3DD86      ; Upload GFX

; Draw Umaro's bones; unpack and upload sprites
C3F072:  JSR C3F036      ; Handle moogles
         JSR C3EF87      ; Unpack skull
         LDY #$6800      ; VRAM pointer
         JSR C3DDB9      ; Upload skull
         LDY #$000A      ; Tiles: 5
         STY $E0         ; Set width
         LDY #$0005      ; Tiles: 5
         STY $E2         ; Set height
         LDX #$0056      ; Src: 7F/0056
         LDY #$3B37      ; Dst: 7E/3B37
         JMP C3EDCD      ; Draw bones

; =============================================================================

; Warn on bank overflow
warnpc $C40000
